Another possibility would be to reverse the creation order of the components.
However, this is not a robust way to generally solve the problem once and for all.
Stevie's ideas are -of course- correct, but I don't like having to add code in each and every event handler for the rest of my (programmers) life just to make sure, I don't get caught in these side effects caused by the loading order of components.
Personally, I would remove the design time links from the component events to the event handlers and add them in the FormActivate, after everything has been loaded. As FormActivate is called each time the form is displayed (i.e. 'activated'), I would also make sure, my initialization code is only called once.
This is a decent and robust design pattern which avoids all those caveats during form initialization:
Delphi-Quellcode:
Procedure TMyForm.MyFormInitialize;
Begin
MyControl.OnDoSomething := MyFormDoSomethingEventHandler;
// ... more init stuff here
End;
Procedure TMyForm.FormActivate(Sender : TObject);
Begin
if not FInitialized Then MyFormInitialize;
FInitialized := True;
End;