Board index » delphi » forms and onshow doesn't work!!

forms and onshow doesn't work!!

Hi,

I have one mainform and another dialog form. Both are auto-create forms.
I press a button on the mainform and pops up the dialog box.
The problem is that I have some code that should execute once the dialog box
is visible. However, when i do this the code is executed before the form is
visible! Doing application.processmessages and putting code in onshow
procedures has no effect. Even sleep(...) doesn't make the form be seen
before the code is executed!

HELP!!!

Thanks,
Gurpal
--
Gurpal Singh Bhachu
Info. Sys. Eng. UG 2
Dept. of Computing,
Imperial College,
180 Queen's Gate
London SW7

Mob: 0956 266619
ICQ: 33484884

 

Re:forms and onshow doesn't work!!


Gurpal S. Bhachu <gurpal.bha...@ic.ac.uk> skrev i en
nyhedsmeddelelse:S11p3.1105$u5.120...@newsr2.u-net.net...

Quote
> I have one mainform and another dialog form. Both are auto-create forms.
> I press a button on the mainform and pops up the dialog box.
> The problem is that I have some code that should execute once the dialog
box
> is visible. However, when i do this the code is executed before the form
is
> visible! Doing application.processmessages and putting code in onshow
> procedures has no effect. Even sleep(...) doesn't make the form be seen
> before the code is executed!

This works as designed. The OnShow event is called just before the form
becomes visible, and it does not becomes visible until OnShow has finished.
The code below makes sure that the form is visible first and then the
WMUSER1 procedure is called.
Try this:

  private
    { Private declarations }
    procedure WMUSER1(var Msg: TMessage); message WM_USER+1;

{This can be FormCreate or FormShow}
procedure TForm1.FormCreate(Sender: TObject);
begin
  PostMessage(Handle, WM_USER+1, 0, 0);
end;

procedure TForm1.WMUSER1(var Msg: TMessage);
begin
  ShowMessage('Delphi is great');
end;

Re:forms and onshow doesn't work!!


Quote
Gurpal S. Bhachu wrote in message ...
>Hi,

>I have one mainform and another dialog form. Both are auto-create
forms.
>I press a button on the mainform and pops up the dialog box.
>The problem is that I have some code that should execute once the
dialog box
>is visible. However, when i do this the code is executed before the
form is
>visible! Doing application.processmessages and putting code in onshow
>procedures has no effect. Even sleep(...) doesn't make the form be seen
>before the code is executed!

This is the normal behaviour. Some time ago, I ran into the same
problem. As a quick and dirty solution I put a Timer component on the
form, which is triggered by OnShow.

-----------------
DelphiLand: tips, source code, tutorials
www.festra.com

Re:forms and onshow doesn't work!!


Put the code in the OnShow event rather than OnCreate.

Other Threads