Solved

Using the timer

Posted on 1998-09-26
16
152 Views
Last Modified: 2010-04-06
I work on a helpdesk. I get regular calls throughout the day. I want to be able to add a persons name into my program and then 30 minutes after this name will pop up on screen as a reminder to myself to deal with his problem. I can do this but after his call I may have entered 5 other calls that also have to pop up after the required time.
Any help or code would be appreciated.
Cheers
Mike Ross
0
Comment
Question by:mykyl
  • 7
  • 2
  • 2
  • +5
16 Comments
 
LVL 2

Expert Comment

by:rene100
Comment Utility
hi mike

her's an idea:
make an integer-array and a string-array.
fill the string-array with the name of the persons, and
the integer-array with the seconds (or minutes) remaining for
the pop-up menu.
the on overy OnTimer procedure, you decrement the amount in the
int-array, and if it is zero, the pop-up is displayed with the name in the string-array

regards
rene
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
you could also create a record...

type
  TPerson = record
    Name : String;
    Time : Integer;
end;

var
  People : array[0..500] of TPerson;
To Clear the Arra()
for i := 0 to 500 do
begin
  People[i].Name := '';
  People[i].Time := 0;
end;

//If there is a new person to add then....
for i := 0 to 500 do
  if (People[i].Name = '')and(People[i].Time = 0)then
  begin
    People[i].Name := TheName;
    People[i].Time := 30;
    break;
  end;

Make a function that decreases the time...

for i := to numpeople do
  if Not(People[i].Time = 0)then
    Dec(Peopl[i].Time);

there are a few more things you have to think about but don't have much time right noe///

Hope this helps a bit....

Regards,
Viktor Ivanov
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
One more thing to add.....This code I gave you above for decreasing the time has to be in the ontimer of the timer....I'll add some code here to display his/her name if the time is 0

for i := to numpeople do
begin
  if Not(People[i].Time = 0)then
         Dec(Peopl[i].Time)
  else
    if Not(People[i].Name = '') then
      ShowMessage('Time to get with ' + People[i].Name + ' and fix his/her problems!');
end;

Regards,
Viktor Ivanov
0
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
Sorry guys, I would prefer using winAPI SetTimer/KillTimer directly:

var NameRec : array of record   // dynamic array (Delphi 4)
                         id   : cardinal;
                         name : string;
                       end;

procedure TimerProc(hwnd: HWND; uMsg, idEvent: cardinal; dwTime: cardinal); stdcall;
begin
  KillTimer(0,idEvent);
  for i1:=0 to NoOfNames-1 do
    if NameRec[i1].id:=idEvent then begin
      YourProcedureToPopupTheName(NameRec[i1].name);
      break;
    end;
end;

procedure AddName(name: string);
begin
  SetLength(NameRec,NoOfNames+1);
  NameRec[NoOfNames].name:=name;
  NameRec[NoOfNames].id:=SetTimer(0,0,ms,@TimerProc);
  inc(NoOfNames);
end;

Regards, Madshi.
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
That's a good one too...Haven't tested it, but if it works I guess it's cool too,,, You can also have a StringList with the name and the time.....

List.Add(Name + '-'+IntToStr(TheTime));

//Vik
0
 
LVL 5

Expert Comment

by:scrapdog
Comment Utility
Since, I would assume that 30 minutes doesn't have to be EXACT in your case (i.e. 29 minutes or 31 minutes would be OK), you could set the timer to an interval of one minute.

With the person's record, include the system date/time when the call occurred.  Then, every minute that the OnTimer event occurs, compare the current system date/time with that of the date/time attached to every call.  If 30 minutes has elapsed, pop up the reminder for that call.

This would eliminate the need to use counters of any kind.  You could set the TTimer to any interval.  If you need more precision, you can decrease the TTimer interval.  For example you could set the interval to thirty seconds (the reminder would be shown sometime between 29:30 and 30:30), fifteen seconds (between 29:45 and 30:15), one second (between 29:59 and 30:01), 2 minutes (between 28:00 and 32:00), and so on.

Just be sure to include a flag with the record of each call that indicates whether the reminder has been shown yet.  This will ensure that your reminder is only shown once.


Scrappy
0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
why not just using the event timer in RxLib?
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
Hello Zif ;->

What's up? You seem to be back :-)

How was the big vacation you took?

Regards,
Viktor Ivanov
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:mykyl
Comment Utility
Ive seen the event timer but cant figure it out.
0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
Hi all,

I'm back from Spain. But still have a week vacation... The vacation was great! I needed it.

Speak you soon.

Zif.
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
I'm happy you liked it :-)

Talk to you later!

//Vik
0
 
LVL 2

Accepted Solution

by:
Thaddy earned 100 total points
Comment Utility
Why not create a timer for everyone of the callers like

Type
   TTimerAndInfo=class(TTimer)
   private
     Fcaller:String;
     FPhone:string;
   public
     constriuctor create(Aonwer:Tcomponent);override;
     procedure Displaymessage(sender:Tobject);
   published
     property Caller:string read Fstring write Fstring;
     property Phone:string read FPhone write Fphone;
   end;
//Finish this yourself, don't forget to connect the
//displaymessage to the Ontimer event.
//

 Now, when you have a caller, Do something like this:
  with TTimerandInfo.Create(Form1) do
    begin
      Timeout:=30*1024;
      Caller:='John Doe';
      Phone:='999';
   end;
You don't have to worry about freeing the timer, because the form will do that for you, unless you manually free it after you handled the response to the call

0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
If you don't free the timer the system will run out of resources if you keep createing timers....

//Vik
0
 
LVL 35

Expert Comment

by:TimYates
Comment Utility
Hurrah!!! Vanishing Icons...

Tim.
0
 
LVL 2

Expert Comment

by:Thaddy
Comment Utility
Try calculating how many calls you can answer in a day...
Vanishing icons won't be due to a couple of timers luring around in your system:)
(I just tried 200 of them simultaneously just to see what happened, silly me)
0
 
LVL 10

Expert Comment

by:viktornet
Comment Utility
You might be able to do that but is not a good way of programming :-|

//Vik
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now