Board index » delphi » Help for "VB to Delphi" user

Help for "VB to Delphi" user

Hopefully someone can assist me with a problem I'm having with forms.
Typically in VB you would close a form with Me.close, further references
to the form would automatically initiate the form create and show
methods.

Why doesn't Delphi do this. When I close a form and then re-show it I
would have expected the controls to have their default (design)
properties not the ones I just told the system to forget.

Is it just a case of putting initialisation code in the onActivate event
rather than the onCreate event which appears to occur at the very start
of program execution.

Sorry if I'm being really stupid.

Cheers.
--
---------------------------------------
John Greening
Gloucestershire UK
---------------------------------------

 

Re:Help for "VB to Delphi" user


The default when closing a form is caHide, which just says hide the form.
in the OnClose event of the form, you can set Action := caFree, which will
destroy the form.

One note of caution.....  When you get rid of this form, it will delete the
object, and will need to be recreated.  So, when you call the Show method
again, you will get an exception.  here is what I would suggest:

Rather than create all forms upfront (the way Delphi does by default), just
create them when you want them.  Each time you would call the Show method,
create the form and then call the Show method.  then destroy it on the way
out.  This is actually a feature, since most people do not want to destroy
and create.

Another alternative is use the Close and Show as you are now, but call the
Destroy/Create methods when needed.

Hope this helps,

Jim Scofield
jscofi...@mindspring.com

John <john...@dircon.co.uk> wrote in article <32B813DC...@dircon.co.uk>...

Quote
> Hopefully someone can assist me with a problem I'm having with forms.
> Typically in VB you would close a form with Me.close, further references
> to the form would automatically initiate the form create and show
> methods.

> Why doesn't Delphi do this. When I close a form and then re-show it I
> would have expected the controls to have their default (design)
> properties not the ones I just told the system to forget.

> Is it just a case of putting initialisation code in the onActivate event
> rather than the onCreate event which appears to occur at the very start
> of program execution.

> Sorry if I'm being really stupid.

> Cheers.
> --
> ---------------------------------------
> John Greening
> Gloucestershire UK
> ---------------------------------------

Re:Help for "VB to Delphi" user


Quote
>  Is it just a case of putting initialisation code in the onActivate event
>  rather than the onCreate event which appears to occur at the very start
>  of program execution.

Yes, move your initialisation to onactivate for the form instead.
Sometimes I have used this to an advantage. I have made programs where people use forms to enter stuff where they quite often
use the same data over and over again in some fields.
So instead of have the initialisation to default values in onactivate I have associated that with a button.onclick event.
So if the person brings up the form again, all things he/she entered the last time will be there automatically.
But if they need the default values they simply press the button labeled "Restore default" and get a clean form.
Otherwise they can reuse what they entered the last time.

johan

Other Threads