In a similar case, I use a Singleton object that stores a list of all created forms. Each form has a field with a link to this object.
TMyForm = class(TForm) private
You can set this link, for example. when calling the constructor:
TMyForm.Create(aFormHandler: TFormHandler; aOwner: TComponent) begin FFormHandler := aFormHandler; inherited Create(aOwner); end;
(Or you can set the field from the outside immediately after creating the form, if you do not want to change the constructor parameters).
When the ist form is destroyed, it notifies the handler and tells it to remove the form from the list - something like this:
TMyForm.Destroy(Sender: TObject); begin FFormHandler.RemoveFromFormList(Self); inherited; end;
(Tracking details are not included in the decryption - for example, the "AddToFomList" method or something similar will be needed)
source share