Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VCL forms issue 1

Status
Not open for further replies.

Snaples

Programmer
May 7, 2007
16
IL
Hi there.
I have this regular vcl form app and i wanted to know if I can see changes made before a form procedure ends.
ex:
procedure TForm1.FormShow(Sender: TObject);
Begin
Memo1.Text := 'blah blah';
Sleep(10000);
Memo1.Text := 'End of blah blah';
End;

But it will only show me the "End of blah blah" text with a delay b4.

Thank in advance.
 
Try doing a Refresh or a Repaint after the first text is written and before the sleep;

Steve [The sane]: Delphi a feersum engin indeed.
 
Thanks for the reply, But I tried them both (Seperately and together), Doesn't work....
it doesnt even open the form...
 
the eternal problem...

here's a solution:

Code:
procedure TForm1.FormShow(Sender: TObject);

var I : integer;

Begin
  Memo1.Text := 'blah blah';
  for I:=1 to 10000 do
   begin
    Application.processmessages; // gives your app the chance to process any messages in its queue (like the WM_PAINT for your label)
    sleep(1);
   end; 
  Memo1.Text := 'End of blah blah';
End;

apply this trick in your code where you suspect that some calculation or whatever could take some time and freeze your UI...

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Code:
procedure TForm1.FormActivate(Sender: TObject);
begin
  Label1.Caption := '1';
  Application.ProcessMessages;
  sleep(2000);
  Label1.Caption := '2';
  Application.ProcessMessages;
  sleep(2000);
  Label1.Caption := '3';
  Button1.Enabled := true;
end;

How's this?
 
I think the problem is the sleep is just that it stop program execution.
To see the text the screen must repaint but these calls are Threaded i.e they dont stop the program flow. So Windows goes off to refresh the screen, but before that can happen you put everything to sleep. When you return from the sleep period its as if it haddent been there and the second text replaces the first so that all you see.

Get round this sort of thing by using a timer event to display the text. Your calling Method just starts the timer.





Steve [The sane]: Delphi a feersum engin indeed.
 
steve the calls are not 'threaded', everything takes place in the same thread. all delphi apps are by default single threaded.

a typical windows application is nothing more than a message pump. offcourse calling sleep (or some time consuming calculation) will prevent your application to read/process the message queue.

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Thanks for every one!!!!

I tried everything until i got to Steve's timer tip.
googled the component a bit and now my app works like a charm!

Thanks again for everything!
 
To see the text the screen must repaint but these calls are Threaded i.e they dont stop the program flow. So Windows goes off to refresh the screen, but before that can happen you put everything to sleep.

The code I posted above works for me (it seems). Shows 1, then 2, then 3 on the form in a label. Is there an issue with that kind of approach?
 
By threaded I don't mean a Delphi 'Thread', as you say Windows is queuing what it allows Delphi and everything else to do, this is what I meant.

A CPU can only do one thing at a time. Even multi core can only output one thing at a time, so if an operating system didn't have some form of Interrupts/Threading call it what you like it would be useless.

I have found that is execution is too quick especially if it is in a loop then ApplicationProccesmessages wont get windows attention on every loop. With my Hardware hat on and programming Micro-controllers you have to be well aware of this sort of thing.

anyway sleep() is pretty inelegant don't you think?





Steve [The sane]: Delphi a feersum engin indeed.
 
Agreed, Sleep is just used here to mimic a time consuming calculation/operation...

My point was that if you want a responsive UI, use processmessages in big loops, if that doesn't help, make use of threads.

/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top