Board index » delphi » should i create forms programaticly?

should i create forms programaticly?

Quote
In article <45dg3t$...@er5.rutgers.edu> khem...@er5.rutgers.edu (Maverick) writes:
>i was wondering if someone knows if you should let your app create all of
>the forms by default when then app is started (this is the default) - then
>all you have to do is "show" them.  or should you create other forms as
>necessary (e.g. when a certain event occurs, like a button click)?

When you create the additional forms as needed, you will be saving system
resources for the forms that are not being used.

A programmer writes code that performs a desired function.  A 'good'
programmer will take control of a program and create what he/she needs when
he/she needs it and considers other aspects of programming like system
resources and re-use of the code in other instances.

Jeff J
---------------------------------------------------------------------
No cute drawings or funny quotes - Just me.

 

Re:should i create forms programaticly?


In article <45dg3t$...@er5.rutgers.edu>,
   khem...@er5.rutgers.edu (Maverick) wrote:

Quote
}
}hi,
}
}i was wondering if someone knows if you should let your app create all of
}the forms by default when then app is started (this is the default) - then
}all you have to do is "show" them.  or should you create other forms as
}necessary (e.g. when a certain event occurs, like a button click)?

        Depends on how much space you're taking up.  If you find yourself
getting stack overflow, might be a good idea to only create them when you need
them.  But the improved user response from just having to show them isn't
something I would give up without a fight.

        Basically, the more likely they are to regularly use a form, the more
you want it loaded up.  A configuration form they only use once every couple
months doesn't need to be there all the time, though.

TG

--
Government is like a baby.  An alimentary c{*word*7}with a big appetite at
one end and no sense of responsibility at the other

-Ronald Reagan

Re:should i create forms programaticly?


Quote
je...@decisionsys.com (Jeff Jacobson) writes:
>In article <45dg3t$...@er5.rutgers.edu> khem...@er5.rutgers.edu (Maverick) writes:
>>i was wondering if someone knows if you should let your app create all of
>>the forms by default when then app is started (this is the default) - then
>>all you have to do is "show" them.  or should you create other forms as
>>necessary (e.g. when a certain event occurs, like a button click)?
>When you create the additional forms as needed, you will be saving system
>resources for the forms that are not being used.
>A programmer writes code that performs a desired function.  A 'good'
>programmer will take control of a program and create what he/she needs when
>he/she needs it and considers other aspects of programming like system
>resources and re-use of the code in other instances.

hello jeff,

i tried creating forms on an "as-needed" basis and found that there was not
a great deal of difference in system resource usage.  however, i did find
that the app took just as long to start, and the user ended up having to
wait for the form to be created before it was displayed.  perhaps i am
doing something wrong, but here is my code:

{SupportingDataForm is set to not auto-create}
{this code is executed when the user clicks on a button}
var
  SupportingDataForm : TSupportingDataForm;
begin
  SupportingDataForm := TSupportingDataForm.Create(self);
  SupportingDataForm.ShowModal;
  SupportingDataForm.Free;
end;

am i forgtting to do something?  perhaps i should not free after the user
is finished.  would it be possible to check if the SupportingDataForm
already exists.  if it does, it is not recreated, but simply shown.  that
way, it only needs to be created once, not over and over everytime the
user wants to show it.  any clues on how to implement this?

thanks,
yash

Quote
>Jeff J
>---------------------------------------------------------------------
>No cute drawings or funny quotes - Just me.

Re:should i create forms programaticly?


Quote
Maverick (khem...@er5.rutgers.edu) wrote:

: hi,

: i was wondering if someone knows if you should let your app create all of
: the forms by default when then app is started (this is the default) - then
: all you have to do is "show" them.  or should you create other forms as
: necessary (e.g. when a certain event occurs, like a button click)?

In general you should create forms when needed and free them afterwards.
This way you'll save resources and the application will start faster.
IMHO there are some cases in which autocreating forms does make good sense:
- forms that are used often
- forms that are to appear immediately (the process of creation
takes some time)
- forms that have components you need although the form is hidden

Regards,
Matthias

----
Matthias Romppel                   email: mrom...@gwdg.de
Institut fuer Psychologie
Gosslerstr. 14
D-37073 Goettingen

Re:should i create forms programaticly?


Quote
khem...@er5.rutgers.edu (Maverick) wrote:
>i tried creating forms on an "as-needed" basis and found that there was not
>a great deal of difference in system resource usage.  however, i did find
>that the app took just as long to start, and the user ended up having to
>wait for the form to be created before it was displayed.  perhaps i am
>doing something wrong, but here is my code:

>{SupportingDataForm is set to not auto-create}
>{this code is executed when the user clicks on a button}
>var
>  SupportingDataForm : TSupportingDataForm;
>begin
>  SupportingDataForm := TSupportingDataForm.Create(self);
>  SupportingDataForm.ShowModal;
>  SupportingDataForm.Free;
>end;

>am i forgtting to do something?  perhaps i should not free after the user
>is finished.  would it be possible to check if the SupportingDataForm
>already exists.  if it does, it is not recreated, but simply shown.  that
>way, it only needs to be created once, not over and over everytime the
>user wants to show it.  any clues on how to implement this?

Yep.

Make SupportingDataForm a member of the class that has the
button-click method, and initialise it to NIL when on object
of that class is created (i.e. in OnCreate, if it's a form)
Then change your button-click code to:
BEGIN
   IF SupportingDataForm = NIL THEN
      SupportingDataForm := TSupportingDataForm.Create (self);
   SupportingDataForm.ShowModal
END;

take your SupportingDataForm.Free call and put it in the OnDestroy
code for your form (checking for NIL is not required before
calling Free, remember).

Hope this helps

Matt

-----------------------------------
Matt Francomb, Setanta Software Ltd
http://www.demon.co.uk/setanta
-----------------------------------

Other Threads