The OnShow event is OnShow just before the ShowWindow Windows API function is ShowWindow . It is this ShowWindow call ShowWindow actually causes a window to appear on the screen.
So, ideally, you need to start something right after calling ShowWindow . It turns out that the VCL code that controls all this is inside the TCustomForm message TCustomForm for CM_SHOWINGCHANGED . This message handler fires the OnShow event, and then calls ShowWindow . Thus, a great solution is to show your modal form immediately after starting the CM_SHOWINGCHANGED handler. Like this:
type TMyMainForm = class(TForm) private FMyOtherFormHasBeenShown: Boolean; protected procedure CMShowingChanged(var Message: TMessage); message CM_SHOWINGCHANGED; end; ..... procedure TMyMainForm.CMShowingChanged(var Message: TMessage); begin inherited; if Showing and not FMyOtherFormHasBeenShown then begin FMyOtherFormHasBeenShown := True; with TMyOtherForm.Create(nil) do begin try ShowModal; finally Free; end; end; end; end;
David heffernan
source share