Lazarus

Using the Lazarus IDE => General => Topic started by: MalabarFlash on June 09, 2018, 03:12:44 pm

Title: Display Caption for several seconds and quit
Post by: MalabarFlash on June 09, 2018, 03:12:44 pm
When the user clicks on the "QUIT" button, I would like the app to display a caption for several seconds and quit the application.  Here is the procedure I used.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.ButtonQuitClick(Sender: TObject);
  2.   LabelBye.Caption := 'Goodbye  Benjamin';
  3.   Sysutils.sleep(2000);
  4.   Application.Terminate;
  5. end;

Swapping the "sleep" and "label" instructions has the same output.  I've tried "wait" and "delay" with the same results.

What do I need to change to get the caption to display for more than a few milliseconds before termination?
Title: Re: Display Caption for several seconds and quit
Post by: Handoko on June 09, 2018, 03:30:17 pm
You need to call Application.ProcessMessages:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.ButtonQuitClick(Sender: TObject);
  2. begin
  3.   LabelBye.Caption := 'Goodbye  Benjamin';
  4.   Application.ProcessMessages;
  5.   Sysutils.sleep(2000);
  6.   Application.Terminate;
  7. end;
Title: Re: Display Caption for several seconds and quit
Post by: MalabarFlash on June 09, 2018, 03:52:16 pm
Thank you Handoko.  That solved my problem.
TinyPortal © 2005-2018