Vervolg van een bericht van Henk Hamers aan Bart Broersma:
Hi.
BB> Here's something I don't quite understand.
BB> Say I have a simple apllication (Delphi 1.0), with Form1 as
BB> the main form. Now I add another form (Form2) to this
BB> project, lets say something like an AboutBox or a simple
BB> Ok/Cancel dialog.
BB> Now, what is the proper way to show this form, which syntax
BB> is correct ?
BB> 1.
BB> Form2.SomeProperty := SomeValue;
BB> Form2.ShowModal;
BB> if Form2.ModalResult = mrOk then ...
BB> ...
BB> 2.
BB> Form2 := TForm2.Create(Application);
BB> Form2.SomeProperty := SomeValue;
BB> Form2.ShowModal;
BB> if Form2.ModalResult = mrOk then ...
BB> ...
BB> Form2.Free;
BB> Both syntaxes seem to work, so I'm a little confused here
BB> (am I missing some fundamental concept here ?).
HH> The first one is the correct one. Why??
HH> Because you earliar stated that you already made the second form
HH> with the IDE (in design mode). In that case you don't have to make
HH> an new instance to get the form (its already created at design
HH> time). In your second case you are making a new form and you will
HH> never free up the form you created at design time!!
And you should never try to free anything which was created by Delphi either.
If you don't remove it from the owner's control list, Delphi will try to free
the thing later when the application is closed and you'll get a GPF / Access
violation.
I personally prefer the second method. It should be a little leaner, no
instance is created until you need one and it will no longer exist and occupy
resources once you don't need it anymore. You should however remove all forms
but the main form from the auto-create list in project options before
compiling your application.
HH> - Origin: Programming PFFF... (2:285/717.28)
Would that be PFFF like "programming is no big deal" or like "programming is
a trying experience" ? :-)
Groeten, Martin.
--- FMail/386 1.02
---------------
* Origin: -=[ E-mail: m_maat@knoware.nl .......... ]=- (2:286/420.1)
|