Recent

Author Topic: Display Caption for several seconds and quit  (Read 2208 times)

MalabarFlash

  • New Member
  • *
  • Posts: 21
Display Caption for several seconds and quit
« 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?

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: Display Caption for several seconds and quit
« Reply #1 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;

MalabarFlash

  • New Member
  • *
  • Posts: 21
Re: Display Caption for several seconds and quit
« Reply #2 on: June 09, 2018, 03:52:16 pm »
Thank you Handoko.  That solved my problem.

 

TinyPortal © 2005-2018