This answers address what I think is the real issue as has become apparent from your comments. You should edit the question to include those details that at the moment appear only in comments.
You appear to be trying to make a procedure run whenever a form is created. As I explained above, no good will come of waiting in the main thread. The thing you are waiting for also runs in the main thread. You'll just block forever.
So I won't attempt to explain how to wait, as you asked, because that can never work. That is not the solution to your real problem.
As I understand your problem, based on your recent questions, you are trying to access Application.MainForm
in the constructor of said form, and the MainForm
property has not yet been initialised. The reason you do that is because you want to walk over all components owned by Application
.
Or you want to use the global Form1
variable which is nil
during the creation of the form. But you would be well advised to delete that global Form1
variable anyway. Global variables tend to cause trouble. Since you are inside the a method of your form, in a method handler for OnCreate
, you can access the form using Self
. Always use Self
if it is possible to do so.
But that's the wrong way to solve the problem anyway. It denies the existence of forms created after your program has started. You should do what you need to do, on demand, when any form is created.
This is how I would solve your problem:
- Declare a new form, derived from
TForm
, called, for instance, TMyBaseForm
.
- Add an
AfterConstruction
procedure, with the override
directive.
- Implement
TMyBaseForm.AfterConstruction
to invoke your text changing code. At this point all the design time control exists and have properties streamed.
- Make sure that all forms in your application derive from
TMyBaseForm
.
This design gives you the opportunity to apply consistent behaviour across all GUI elements in your program.
One final comment. You appear to be relatively inexperienced and novice. That's fine, we were all there once. But you will be more successful if you ask questions about your problem rather than about your proposed solution.