Jump to content
Ricardo

Header Control and menu

Recommended Posts

HI.

 

I have this code and works ok (on application declaration unit)

FHeader := TW3HeaderControl.Create(Display);
  FHeader.SetBounds(5, -10, 100, 40);
  FHeader.Caption := 'xxxxxx';
  FHeader.BackButton.Caption := '←';  //arrow left
  FHeader.NextButton.Caption := '☰'; //hamburger menu

  FHeader.NextButton.OnClick := createMenu;
...

procedure TApplication.CreateMenu(Sender: TObject);
begin

   FfrmMenu := TfrmMenu.Create(Application.Display.View);
   FfrmMenu.Name := 'MainMenu';
   Application.RegisterFormInstance(FfrmMenu, true);
   Application.GotoForm('MainMenu', feFromRight);
   Application.GotoForm('MainMenu', feFromRight);

end;

(the menu appears when i press next button, but the header is visible on login form .)

And this one that does not

FHeader := TW3HeaderControl.Create(Display);
  FHeader.SetBounds(5, -10, 100, 40);
  FHeader.Caption := 'xxxxxx';
  FHeader.BackButton.Caption := '←';  //arrow left
  FHeader.NextButton.Caption := '☰'; //hamburger menu

  FHeader.NextButton.OnClick := OpenMenu;
   
...
  createMenu(Application)

procedure TApplication.CreateMenu(Sender: TObject);
begin
if FfrmMenu = nil then
   begin

  ShowMessage('Control 0'); //show message
   FfrmMenu := TfrmMenu.Create(Application.Display.View);
   FfrmMenu.Name := 'MainMenu';
   Application.RegisterFormInstance(FfrmMenu, true);  
   end;
end;

procedure TApplication.OpenMenu;
begin

ShowMessage('Control 1');    //show message
Application.GotoForm('MainMenu', feFromRight);    //don't show form menu

ShowMessage('Control 2'); //show message
end;

The objective is to open a login form with the header not enabled and, if the password is correct, enable the header and see a menu when clicking on the next button.

I do not see what I'm doing wrong

 

Share this post


Link to post
Share on other sites

If you have designed the loginform via the normal designer (e.g "form2"), then you dont need to register it.
All designed forms are auto-registered (if you right-click on the project node in the project-treeview, there is a "view source" option that shows the startup code for you).

But, I think you want to use a modal dialog approach.

In the Application, there is a modal-dialog function that can show a second form -over the present form.
It will also grey out the real mainform (disabled), so it cant be clicked - until you have closed the modal-dialog.

So typically you would have two edit-boxes, username + password, and a cancel or "login" button on that form.
And the user wont get access to the underlying mainform until he has provided the correct password

So in the loginform you would close it by calling: 

application.HideModal(mrOK); //or mrCancel if it failed

And from the main form you would call this to show your modal-form (see code for better description of the params)

  Application.ShowModal(loginform, nil, nil,
  procedure (dialog: TW3CustomForm)
  begin
    // Write code to execute just after the dialog is showing
  end,

  procedure (Dialog: TW3CustomForm)
  begin
    // this code fires when modalresult = mrOK
  end,

  procedure (Dialog: TW3CustomForm)
  begin
    // this code fires when modalresult = mrCancel
  end);

 

 

Share this post


Link to post
Share on other sites

I do not have the problem in the registration of the forms, but in the first way that I indicate, if it works but in the second it does not.
That is, when I follow these instructions (https://jonlennartaasenden.wordpress.com/?s=header) everything works correctly. But if I want to separate the creation of the header and its visualization, it does not work.
To fix it, I have moved the createMenu execution to the Login form, after the password verification.
(I guess I do not explain myself very well, I use Google translator and something will be lost)

Share this post


Link to post
Share on other sites

Normally, in Delphi, I use the Application Event Manager.....but, before that existed in Delphi, I did it all by hand....which you can do here.

Just create some way to test for a valid password (e.g.  passwordisValid function)

Then create your procedure to update anything in the GUI that needs updating based in the validation test (e.g. updating the Next button on the GUI)

Then call the UpdateGuI procedure where it needs to be called

e.g.  When the form is first activated

        Everytime the password edit box changes


 

  TLogInForm = class(TW3Form)
    procedure W3EditBox1Changed(Sender: TObject);
  private
    {$I 'LogInForm:intf'}
    function passwordIsValid: Boolean;
  protected
    procedure InitializeForm; override;
    procedure InitializeObject; override;
    procedure Resize; override;
  public
    procedure UpdateGUI;
  end;

function TLogInForm.passwordIsValid: Boolean;
begin
 result:=       //add your check here so that it returns true if its a valid password
end;

procedure TLogInForm.W3EditBox1Changed(Sender: TObject);
begin
  UpdateGUI;
end;

procedure TLogInForm.UpdateGUI;
begin
 W3HeaderControl1.NextButton.Enabled:= passwordIsValid;
end;

procedure TLogInForm.InitializeForm;
begin
  inherited;
  // this is a good place to initialize components
  UpdateGUI;
end;

 

Share this post


Link to post
Share on other sites

IElite is absolutely correct. Sorry if I misunderstood you, I was under the impression that it was the actual showing you had a problem with.
Adding an event to the dialog form, or proper methods like IElite does - is the way to go.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...