Recent

Author Topic: Open and close a Form  (Read 5519 times)

ironman_br

  • Newbie
  • Posts: 2
Open and close a Form
« on: April 11, 2006, 07:24:08 pm »
I´m tryng to do this, but don´t work

How I can do this?

procedure TJPrincipal.CheckBoxAQEextraChange(Sender: TObject);
var
  FormAQEOptions: TFormAQEOptions;
begin
  {FormAQEOptions := TFormAQEOptions.Create(self);
  If (CheckBoxAQEextra.Checked = True) then
     FormAQEOptions.Visible := True else
     begin
        FormAQEOptions.Visible := False;
        FormAQEOptions.Close;
        FormAQEOptions.Release;
        Label4.Caption := ':P';
     end;
          }
end;

johnf

  • New Member
  • *
  • Posts: 18
RE: Open and close a Form
« Reply #1 on: April 11, 2006, 08:22:20 pm »
It look like you are trying to open a form.  You have to 'show' the form.

John

ironman_br

  • Newbie
  • Posts: 2
RE: Open and close a Form
« Reply #2 on: April 11, 2006, 08:38:24 pm »
How I cad do It Right?

i tryed:

procedure TJPrincipal.CheckBoxAQEExtrachangeClick(Sender: TObject);
var
FormAQEOptions: TFormAQEOptions;
begin
     FormAQEOptions := TFormAQEOptions.Create(self);
     If (CheckBoxAQEextra.Checked = True) then
     FormAQEOptions.Show else
     begin
          FormAQEOptions.Hide;
          FormAQEOptions.Destroy;
     end;

end;

He show the form, but don´t hide ;P

Anonymous

  • Guest
Open and close a Form
« Reply #3 on: April 11, 2006, 09:17:17 pm »
Hi Friend.

For destroy the form try this code in the event OnClose

procedure TFormAQEOptions.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
   CloseAction:=caFree; // This constant Destroy the form
end;                             // if you wish view can create again

Regards.

matthijs

  • Hero Member
  • *****
  • Posts: 537
Open and close a Form
« Reply #4 on: April 12, 2006, 08:05:32 am »
It looks like the form only needs to be created and shown if the checkbox is true. So I would do this in the following way:
Code: [Select]

var
  FormAQEOptions: TFormAQEOptions;
 
procedure TJPrincipal.CheckBoxAQEExtrachangeClick(Sender: TObject);
begin
  If (CheckBoxAQEextra.Checked = True) then begin
    if not Assigned(FormAQEOptions) then
      FormAQEOptions := TFormAQEOptions.Create(self);
    FormAQEOptions.Show;
  end else begin
    if Assigned(FormAQEOptions) then FormAQEOptions.Close;
  end;
end;


Please check this code as I have no Lazarus at the moment to test it myself. :) But it will give the general idea of how to do this.
Important is to put the var declaration out of the method for this to work correctly, because otherwise it will go out of scope when the procedure ends. This will make subsequent calls to this method fail.
What's in a sig? Would my posting look less if it didnot have a sig? (Free after William S.) :)

:( Why cannot I upload my own Avatar? :(

 

TinyPortal © 2005-2018