From looking at the source in forms.pas (Delphi 2009), it appears that they create a "master" window in win32 gui apps to allow calls to
- TApplication.Minimize
- TApplication.Restore
- etc
It appears that messages passed to the Application.Handle
are forwarded as appropriate to the MainForm
, if it exists. This would allow the app to respond to minimize, etc if the main window has not been created. By modifying the project source you can create a delphi app without a main window.
In this case, the TApplication
methods will still work, even if you haven't created a main window. Not sure if I'm grasping all of the purposes, but I don't have time to go through all of the TApplication code.
Per your questions:
Where does it come from? It is the handle of a window created in
TApplication.Create
What windows handle is it? a fake window that every gui delphi app requires as part of the TApplication abstraction
Is it the windows handle of the appliation's main form No
If its not the handle of application's mainform then what is it? See above
more importantly: why is it the ultimate parent of every form? assuming you're right that its the ultimate parent, i assume that it is so because it makes it easy to find all of forms in your application (enumerating the children of this "master" form).
and most important: why does everything go haywire if i try to have a form be unparented i think because the hidden "master" form is getting system messages that it should pass on to its children and/or the mainform, but can't find the unparented form.
Anyway, that's my take on it. You can probably learn more by looking at the TApplication declaration and code in forms.pas
. The bottom line from what i see is it is a convenient abstraction.
Best regards,
Don