Board index » cppbuilder » When a form appears for the first time

When a form appears for the first time


2007-11-03 05:56:51 PM
cppbuilder71
Hi all,
I've created several forms (no mainform) very heavy (with many components),
in run-time, when a form appears the first time, the process for show it is
slow, I think because the components are built;
Do exists a procedure for to do this operation when the construction of the
form is called?
The startup will be more slow, but the effect will be always the same.
Thanks in advance.
Bye
 
 

Re:When a form appears for the first time

Form streaming is already performed at construction.
Please post the CPP/H/DFM for one of the forms to
"borland.public.attachments" and I'll take a look at it. Preferably send a
form that has only standard VCL components on it.
Clayton
 

Re:When a form appears for the first time

Hi Clayton,
I have found the cause, but not the solution:
when a form is showed (Visible=true), is executed the OnResize event (but
only the first time), and this rebuild all the components.
I would want to force the resize procedure at startup, but I don't know to
do.
I tried with "Resize()" in AfterConstruction area: the event OnSize is
executed, but when I show my form, the OnResize event is executed again.
Thank you
 

{smallsort}

Re:When a form appears for the first time

"Danny" < XXXX@XXXXX.COM >wrote:
Quote

T{*word*220} posts is greatly apprieciated. Thank you! However,
t{*word*220} too much is not. I had to backup to see what Clayton
had to say.
Quote
I have found the cause, but not the solution: when a form is
showed (Visible=true), is executed the OnResize event (but
only the first time), and this rebuild all the components.

I would want to force the resize procedure at startup, but I
don't know to do.
The solution is to set the TForm's Width or Height and let the
setter methods take over (which will trigger OnResize). For
example:
Width = Width - 1;
or
Width = Width + 1;
or
Height = Height + 1;
or
Height = Height - 1;
I used a variance in the above because it's logical. In most
setter methods, if the new width is the same as the old width,
no action is taken. Thus the variance of one ... forcing the
event.
Quote
[...] but when I show my form, the OnResize event is
executed again.
Oh no! I thought that OnResize didn't execute often enough
and now it seems as though you're saying that it executes
too often.
Please clerify.
~ JD
 

Re:When a form appears for the first time

Hi JD,
I have a form (no mainform) with many graphic components (derived form
TGraphicControl), and when there is the OnResize event, the application
freezes for a few seconds; I have set "MyForm->BorderStyle=bsSingle" for to
avoid that user tries to resize, but I know that is however necessary a
first resize for initialize the form.
I've noticed that the first OnResize event is generated when the form coming
to visible; and so, I looked a way for to anticipate this event (for example
in construction zone).
I have tried with Width=Width+1 in AterConstruction procedure, and yes, I
have the OnResize event, but this has not been enough for avoid that when
switch in "MyForm->Visible=true" the event is generated however. This
because, in costruction zone the sizes of components arent't set, while when
the form coming to visible, the sizes are set.
If I succeed, to execute the same steps before displaying the form, I could
to simulate an initialization.
I know that this is a marginal problem, but it is just a fineness.
I'm sorry for my English, I hope to have exposed well the problem.
Thank you
 

Re:When a form appears for the first time

Hi Danny
If You put a bool Initialized int the H file
set it to false in the constructor and then in the
OnResize You do like this:
if(Initialized)return;
Initialized = true;
the rest of You code.
I don't understand why You use the OnResize event at
all when the is bsSingle. If it is to initialize
dynamic created component You could use the Form OnShow
event in stead it is only called once, just before
the form is shown.
I am sory if I have have misunderstood You, if so
maybe You could upload the form.h and .cpp file to
borland.public.attachments
Kind regards
Asger
 

Re:When a form appears for the first time

Hi Asger,
I've solved with a simple way; I've forced the bound rect of the heaviest
components in AfterConstruction procedure, so when the OnResize event is
called, the component is already initialized.
Thank however.
Bye
 

Re:When a form appears for the first time

On or about Sun, 4 Nov 2007 11:59:39 +0100 did Asger Jørgensen
< XXXX@XXXXX.COM >dribble thusly:
Quote
I don't understand why You use the OnResize event at
all when the is bsSingle. If it is to initialize
dynamic created component You could use the Form OnShow
event in stead it is only called once, just before
the form is shown.
OnShow can also be called more than once in the lifetime of the form.
I use a boolean indicator like you suggest in that event for all bits
of code that need to run once during the lifetime of the form, except
for those things I'm sure will run fine in the constructor.