What may and don't I may do in FormCreate()?
delphi
Solution
There's no definitive documentation giving the list of all the things you can do and connot do in a form's OnCreate.
As for whether or not the .dfm file has been processed and all the form's owned components created, yes they have.
I wouldn't place much store in the code you have found. Calling Sleep during start up, to make the main thread wait, is absolutely not good practice. If the code wanted to wait for another thread it could block for that thread, or wait to get a message from that thread. This just looks like code that got put in by someone who didn't understand what he/she was doing. And the code never got removed.
The other line of code is reasonable:
PostMessage(Handle, UM_PROGRAM_START, 0, 0);
Because this message is posted, it won't get processed until the application starts pumping messages. That happens when you call Application.Run in your .dpr file. Which means that everything related to the creation of you main form happens before that message is pulled off the queue.
Problem
I think this must be a FAQ, but googling hasn't really helped. What may I do - and may do not - in `FormCreate()`? I am wondering if all of the form's child controls are fully created and available for access, etc. The reason I ask is that I stumbled over an old project where my `FormCreate()` simply consists of ``` Sleep(1000); PostMessage(Handle, UM_PROGRAM_START, 0, 0); ``` It seems that I want to "wait a bit" and then do some initialization "when things have settled down" ... Surely I had a reason for it at the time(?), but, in the absence of an enlightening comment I am unable to recall why I felt that to be necessary. Can anyone state, or reference a link which states, any restrictions on what one may do in `FormCreate()`? [Update] I think thta DavidHefferman found the solution when he wrote "the application starts pumping messages. That happens when you call Application.Run in your .dpr file". I guess that I wasn't concerned about a single form. For instance, my main form wants to do somethign with my config/options form at start up, so obviously would have to wait until it is created. Here's a typical .DPR from one of my projects ... ``` Application.Initialize; Application.CreateForm(TGlobal, Global); Application.MainFormOnTaskbar := True; Application.CreateForm(TMainForm, MainForm); Application.CreateForm(TLoginForm, LoginForm); Application.CreateForm(TConfigurationForm, ConfigurationForm); //[snip] a bunch of other forms ... Application.Run(); ``` So, it makes sense for my app's `mainForm.CreateForm()` to send a `UM_APPLICATION_START` to itself which it won't process until all forms are created & initialized (or, I could just call the fn() which the message triggers from my .DPR after `Application.Run()` is called; but I prefer the message as it is more obvious - I rarely look at my .DPR files).