Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-06

Application.onChangeComponentCount ?

7 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Fred van Stappen

Hello.

Is there a plan to add a function like Application.onChangeComponentCount ?

I want to catch a signal when a new form is created (or deleted). I know that the best way is to create a parent form and from this use the form.oncreate event. But if the form has no parent the only way to know if a new form was created (or deleted) is to check if Application.ComponentCount was changed. (with a timer) So i will be happy if a function like "Application.onChangeComponentCount" is added in Application class.

But maybe there is a other way to know if a new form was created (or deleted) ?

Thanks.

Sven Barth
to Fred van Stappen
Fred van Stappen wrote 17 lines
Hello. Is there a plan to add a function like Application.onChangeComponentCount ? I want to catch a signal when a new form is created (or deleted). I know that the best way is to create a parent form and from this use the form.oncreate event. But if the form has no parent the only way to know if a new form was created (or deleted) is to check if Application.ComponentCount was changed. (with a timer) So i will be happy if a function like "Application.onChangeComponentCount" is added in Application class. But maybe there is a other way to know if a new form was created (or deleted) ?

You should ask this on the Lazarus list. TApplication is part of the LCL not the FCL.

Regards,
Sven

Fred van Stappen
to Sven Barth
Show quoted text 29 lines
Date: Sat, 15 Jun 2013 13:34:52 +0200 From: To: Subject: Re: [fpc-pascal] Application.onChangeComponentCount ? On 15.06.2013 12:11, Fred van Stappen wrote: > > > Hello. > > Is there a plan to add a function like Application.onChangeComponentCount ? > > I want to catch a signal when a new form is created (or deleted). > I know that the best way is to create a parent form and from this use > the form.oncreate event. > But if the form has no parent the only way to know if a new form was > created (or deleted) is to check if Application.ComponentCount was > changed. (with a timer) > So i will be happy if a function like > "Application.onChangeComponentCount" is added in Application class. > > But maybe there is a other way to know if a new form was created (or > deleted) ? You should ask this on the Lazarus list. TApplication is part of the LCL not the FCL. Regards, Sven
//////////////////////
TApplication is part of the LCL not the FCL.

Aaargh, ok, so sorry to disturb (but i will be happier if TApplication was part of FCL). ;-)

A

Sven Barth
to Fred van Stappen
Fred van Stappen wrote 37 lines
> Date: Sat, 15 Jun 2013 13:34:52 +0200 > From: > To: > Subject: Re: [fpc-pascal] Application.onChangeComponentCount ? > > On 15.06.2013 12:11, Fred van Stappen wrote: > > > > > > Hello. > > > > Is there a plan to add a function like Application.onChangeComponentCount ? > > > > I want to catch a signal when a new form is created (or deleted). > > I know that the best way is to create a parent form and from this use > > the form.oncreate event. > > But if the form has no parent the only way to know if a new form was > > created (or deleted) is to check if Application.ComponentCount was > > changed. (with a timer) > > So i will be happy if a function like > > "Application.onChangeComponentCount" is added in Application class. > > > > But maybe there is a other way to know if a new form was created (or > > deleted) ? > > You should ask this on the Lazarus list. TApplication is part of the LCL > not the FCL. > > Regards, > Sven ////////////////////// > TApplication is part of the LCL not the FCL. Aaargh, ok, so sorry to disturb (but i will be happier if TApplication was part of FCL). ;-)

No, because TApplication needs references to GUI related things (e.g. on Windows a reference to a hidden application window). The FCL is not about GUI, so TApplication has no place there. For programs that don't need a GUI you can take a look at TCustomApplication in unit CustApp however (which TApplication also inherits from).

Regards,
Sven

Fred van Stappen
to Sven Barth: You should ask this on the Lazarus list. TApplication is part of the LCL not the FCL. Sven
Show quoted text 26 lines
> > Hello. > > Is there a plan to add a function like Application.onChangeComponentCount ? > > I want to catch a signal when a new form is created (or deleted). > I know that the best way is to create a parent form and from this use > the form.oncreate event. > But if the form has no parent the only way to know if a new form was > created (or deleted) is to check if Application.ComponentCount was > changed. (with a timer) > So i will be happy if a function like > "Application.onChangeComponentCount" is added in Application class. > TApplication is part of the LCL not the FCL. Aaargh, ok, so sorry to disturb (but i will be happier if TApplication was part of FCL). ;-) No, because TApplication needs references to GUI related things (e.g. on Windows a reference to a hidden application window). The FCL is not about GUI, so TApplication has no place there. For programs that don't need a GUI you can take a look at TCustomApplication in unit CustApp however (which TApplication also inherits from). Regards, Sven

Many thanks Sven, but, if i understand well, TApplication is herited from TCustomApplication.

And in TCustomApplication there is addobject property. So maybe it could be possible to know if a new object was created at runtime (or deleted)? And all that without TApplication, directly with fp ?

But maybe i dream, i have to add a new function in LCL TApplication like : TApplication.onComponentCountChange...

PS : I have ask it to Delphi forum too, the answer was : no, it is not possible to know if a new form was created/deleted, the only way is to create a custom form with custom onCreate and onDestroy and deal with this child forms.

PS2 : But fpc is much powerfull than Delphi, so, maybe... ;-)

Mattias Gaertner
to Fred van Stappen
Show quoted text 13 lines
> > > > Hello. > > > > Is there a plan to add a function like Application.onChangeComponentCount ? > > > > I want to catch a signal when a new form is created (or deleted). > > I know that the best way is to create a parent form and from this use > > the form.oncreate event. > > But if the form has no parent the only way to know if a new form was > > created (or deleted) is to check if Application.ComponentCount was > > changed. (with a timer)
In LCL you can use this:
Screen.AddHandlerFormAdded(@OnFormAdded);

All forms are added to Screen, including those owned by Application.

Mattias

Fred van Stappen
to Mattias Gaertner
Show quoted text 29 lines
Date: Mon, 17 Jun 2013 21:16:59 +0200 From: To: Subject: Re: [fpc-pascal] Application.onChangeComponentCount ? On Mon, 17 Jun 2013 20:57:33 +0200 Fred van Stappen wrote: > > > > > > > > Hello. > > > > > > Is there a plan to add a function like Application.onChangeComponentCount ? > > > > > > I want to catch a signal when a new form is created (or deleted). > > > I know that the best way is to create a parent form and from this use > > > the form.oncreate event. > > > But if the form has no parent the only way to know if a new form was > > > created (or deleted) is to check if Application.ComponentCount was > > > changed. (with a timer) In LCL you can use this: Screen.AddHandlerFormAdded(@OnFormAdded); All forms are added to Screen, including those owned by Application. Mattias

Magnifique, many thanks Mattias. ;-)

Humm, no idea how to do for console application ( like application using fpGUI ?).