Board index » delphi » Form doesn't paint

Form doesn't paint

Hello,

When user click a button, I open (showmodal) new form with progress
bar and stop button. In new form onActivate, I call procedure for some
'heavy' calculations. Problem is that form doesn't always show until
job is done. I try repaint, refresh, processmessages... no success.

Any ideas?
(D6)

Thanks

 

Re:Form doesn't paint


Quote
lot wrote:
> When user click a button, I open (showmodal) new form with progress
> bar and stop button. In new form onActivate, I call procedure for some
> 'heavy' calculations. Problem is that form doesn't always show until
> job is done. I try repaint, refresh, processmessages... no success.

Use a custom window message and post this message in your FormActivate. Take
your heavy calculations code to the message handler. This ensures that all
paint (and other) messages get handled before your code. It's ugly, but
worked for me when I met similar problems.

const
    WM_MYMESSAGE = WM_USER + 200;

type
  TForm1 = class(TForm)
    procedure FormActivate(Sender: TObject);
    procedure MyFormActivate(var message: TMessage); message WM_MYMESSAGE;
  end;

procedure TForm1.FormActivate(Sender: TObject);
begin
    PostMessage(Self.Handle, WM_MYMESSAGE, 0, 0);
end;

procedure TForm1.MyFormActivate(var message: TMessage);
begin
    // do your heavy calculations here.
end;

There could be some errors in this code, but I think the concept is clear.

--
www.zenobits.com

Other Threads