Forum > General
Using multiple forms
dani.user:
Hello
I am new to lazarus. I want to ask you how I could do something like this: I have created 2 forms and I want to show the second one when I click on a button on the first form.
Thank you
theo:
File -> New Form
then in Unit1
--- Code: ---...
implementation
uses Unit2;
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.ShowModal;
end;
...
--- End code ---
matthijs:
I usually remove all forms (except main form) from autocreate list. So therefor I would prefer to do it like this:
--- Code: ---
procedure TForm1.Button1Click(Sender: TObject);
begin
Form2 := TForm2.Create(nil);
try
Form2.ShowModal;
finally
Form2.Free;
end;
end;
--- End code ---
My opinion is, that this is safer, as you can never be sure when the user clicks on Button1 Form2 is assigned.
theo:
--- Quote from: "matthijs" ---I usually remove all forms (except main form) from autocreate list.
---
My opinion is, that this is safer, as you can never be sure when the user clicks on Button1 Form2 is assigned.
--- End quote ---
I don't understand your comment and why you want to make it more complicated than necessary for dani.user.
Why shouldn't Form2 be assigned?
CCRDude:
When you've reached a dozen forms or so, it makes sense from a memory consumption point to create modal forms dynamically.
Anyway, I only see Form2.ShowModal; mentioned (which means a modal dialog - the user can't get back to the main form until he closes Form2) - but whether dani.user wanted a modal or nonmodal dialog (just Form2.Show) is still unclear, so this discussion may be unnecessary :D
Navigation
[0] Message Index
[#] Next page