Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
how to Queue up message forms in a TStringList Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
28-Oct-02
Category
VCL-Forms
Language
Delphi 2.x
Views
88
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

I use a timer to check some conditions. If something special happens, I display a 
message form (using MyMessage.ShowModal, because I need an answer from the user). 
The timer goes on, so several of this Messages could be displayed simultaneously. 
What I want to do: Queue this messages and just display one. If the message is 
done, the next one is to be displayed.

Answer:

Simple idea: Instead of immediately popping up each message, queue them up into a 
stringlist. With a second timer (set to an appropriate interval) , process the 
message list, and delete/ take action. See example below (variations with enabling/ 
disabling timer2 are possible)

1   procedure TForm1.FormCreate(Sender: TObject);
2   begin
3     MsgList := TStringList.Create;
4   end;
5   
6   procedure TForm1.FormDestroy(Sender: TObject);
7   begin
8     MsgList.Free;
9   end;
10  
11  {check for abnormal conditions}
12  
13  procedure TForm1.Timer1Timer(Sender: TObject);
14  const
15    msgNumber: integer = 0;
16  begin
17    if Random > 0.5 then
18    begin
19      MsgList.Add('message ' + IntToStr(msgNumber) + ' @ ' + TimeToStr(Now));
20      inc(MsgNumber);
21    end;
22  end;
23  
24  {process messages}
25  
26  procedure TForm1.Timer2Timer(Sender: TObject);
27  begin
28    Timer2.Enabled := false; {extremely important !}
29    while MsgList.Count > 0 do
30    begin
31      {show oldest messages first}
32      ShowMessage(MsgList[0] + ' viewed @' + TimeToStr(Now));
33      MsgList.Delete(0);
34      {your specific actions ...}
35    end;
36    Timer2.Enabled := true;
37  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC