I want to find a way to know that a form was created at run time (or destroyed). This for Delphi or fpc. Many thanks
PS : Is there a way to retrieve that info for all objects ?
I want to find a way to know that a form was created at run time (or destroyed). This for Delphi or fpc. Many thanks
PS : Is there a way to retrieve that info for all objects ?
In MS Windows you can hook events of your process using this small template:
HSHELL_WINDOWCREATED will inform you that your process was create new window.
Call
InitShellHook
with your procedure address (seeHOOCPROC
declaration).There are no built in events that fire whenever an object is created or destroyed.
Because I like writing code hooks, I offer the following unit. This hooks the
_AfterConstruction
method in theSystem
unit. Ideally it should use a trampoline but I've never learnt how to implement those. If you used a real hooking library you'd be able to do it better. Anyway, here it is:Assign a handler to
OnAfterConstruction
and that handler will be called whenever an object is created.I leave it as an exercise to the reader to add an
OnBeforeDestruction
event handler.Note that I am not saying that such an approach is a good thing to do. I'm just answering the direct question that you asked. You can decide for yourself whether or not you want to use this. I know I would not do so!
Use
TForm
'sOnCreate
event to inform whoever you want in whatever way you want.