2008. október 12., vasárnap

Wait until a TForm is actually painted on screen


Problem/Question/Abstract:

How can I wait until the form is actually painted on screen, before starting the processing so that I can be sure that any exceptions are displayed after the form is painted. I've considered a short timer in the OnCreate. Is there a better way (i.e. catching a Windows message)?

Answer:

Use an custom message:

const
  UM_AFTERSHOW = WM_USER + 1001;

type
  TMyForm = class(TForm)
    procedure FormShow(Sender: TObject);
  private
    procedure UMAfterShow(var Msg: TMessage); message UM_AFTERSHOW;
  end;

implementation

procedure TMyForm.FormShow(Sender: TObject);
begin
  PostMessage(Self.Handle, UM_AFTERSHOW, 0, 0);
end;

procedure TMyForm.UMAfterShow(var Msg: TMessage);
begin
  {your code here}
end;

Nincsenek megjegyzések:

Megjegyzés küldése