Board index » delphi » Is this nuts or am I Ok Here (Creating Forms)

Is this nuts or am I Ok Here (Creating Forms)

My program is getting bogged down with forms and takes forever
loading.

I taken all the  Application.CreateForm statements except the main
form out of the programs start up file and moved the into the forms
themselves. When I need a form I create it, then free it up when it's
finished. Is this Ok or an I playing with fire here?

Sample from inside a form:

  Application.CreateForm(TFormPasswordEnter, FormPasswordEnter);
  FormPasswordEnter.ShowModal;
  FormPasswordEnter.Free;

The program certainly starts up nice and fast. I hope I'm on the right
track here.

Cheers
Don

 

Re:Is this nuts or am I Ok Here (Creating Forms)


Quote
In article <glv7es088vtnkg6rvd127odfq7mecv4...@4ax.com>, Don <donwa...@thezone.net> wrote:

>My program is getting bogged down with forms and takes forever
>loading.

>I taken all the  Application.CreateForm statements except the main
>form out of the programs start up file and moved the into the forms
>themselves. When I need a form I create it, then free it up when it's
>finished. Is this Ok or an I playing with fire here?

>Sample from inside a form:

>  Application.CreateForm(TFormPasswordEnter, FormPasswordEnter);
>  FormPasswordEnter.ShowModal;
>  FormPasswordEnter.Free;

I'm sure this would work, but there's a "safer" way.

First up, wrap everything in a "try...finally" block, in case something goes
wrong.

Second, if you create your form manually (using its constructor, rather than
Application.CreateForm) it might be a tad faster, since no ownership is
implied.

So your code becomes:

FormPasswordEnter := TFormPasswordEnter.Create(nil);
try
   FormPasswordEnter.ShowModal;
finally
   FormPasswordEnter.Free;
end;

Note that this can be accomplished without the variable at all, thusly:

with TFormPasswordEnter.Create(nil) do
try
   ShowModal;
finally
   Free;
end;

Hope this helps,
Mab

|~\  /~| /~~| |~|   The .sig wears a ring of polymorph! --More--
|  \/  |/ / |_| |__ The .login hits! The .cshrc bites!
|      ' /| |_| | / ____________________________________________
| |\/|  /\  | |  /  Official member of STI:
| |  |_/  \_| | /       The Search for Terrestrial Intelligence!
-\|-----------|/------------------------------------------------
=================== http://members.dingoblue.net.au/~mabster ===

Re:Is this nuts or am I Ok Here (Creating Forms)


Quote
> I taken all the  Application.CreateForm statements except the main
> form out of the programs start up file and moved the into the forms
> themselves. When I need a form I create it, then free it up when it's
> finished. Is this Ok or an I playing with fire here?

Yes, I prefer this way much more. It reduces the cost of system
resource.

Quote

> Sample from inside a form:

>   Application.CreateForm(TFormPasswordEnter, FormPasswordEnter);
>   FormPasswordEnter.ShowModal;
>   FormPasswordEnter.Free;

You can just do:
FormPasswordEnter := TFormPasswordEnter.Create(self);
FormPasswordEnter.ShowModal;
FormPasswordEnter.Free;

Quote
> The program certainly starts up nice and fast. I hope I'm on the right
> track here.

That's the truth I aware of.

Evan

Re:Is this nuts or am I Ok Here (Creating Forms)


Thanks for the input folks. Good of you to take the time to respond.
I'm glad this is the right direction because the load time is much
nicer now.

Cheers
Don

On 30 Mar 2000 19:33:09 -0600, Don <donwa...@thezone.net> wrote:

Quote

>My program is getting bogged down with forms and takes forever
>loading.

>I taken all the  Application.CreateForm statements except the main
>form out of the programs start up file and moved the into the forms
>themselves. When I need a form I create it, then free it up when it's
>finished. Is this Ok or an I playing with fire here?

>Sample from inside a form:

>  Application.CreateForm(TFormPasswordEnter, FormPasswordEnter);
>  FormPasswordEnter.ShowModal;
>  FormPasswordEnter.Free;

>The program certainly starts up nice and fast. I hope I'm on the right
>track here.

>Cheers
>Don

Other Threads