Lazarus

Programming => General => Topic started by: Mark12345 on April 11, 2021, 06:03:48 am

Title: timer delphi
Post by: Mark12345 on April 11, 2021, 06:03:48 am
(i just want to do a game of who writes the word faster) store it in an array and then show in a memo1
the timer should start in 0, then start the timer and when the person writes the word it will be stored in an array and then  show it in a memo1 finally the timer stops(all of this with repeat)
i want to save the timer expressed in hours minutes and seconds

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. type
  3. people=array[1..2] of string;
  4. peopletime=array[1..2] of integer;
  5. var
  6.   string1,text:string;
  7.   time:integer;
  8.   k:integer;
  9.   p:people;
  10.   p1:peopletime;
  11. begin
  12. memo1.Lines.Clear;
  13. k:=1;
  14. p[1]:='James';
  15. p[2]:='Dan';
  16.    repeat
  17.    timer1.Interval:=1000; //i donĀ“t know what this thing do but i
  18.    searched on the net and i think i need it
  19.    timer1.Enabled:=true;
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.     string1:='day';
  28.     text:=inputbox('enter the word',string1,'');
  29.     if text='day' then
  30.      begin
  31.      p1[k]:=//save the time here in hours minutes and seconds;
  32.      memo1.Lines.add('the time of'+' '+(p[k])+' '+'was'+' '+inttostr(p1[k]));
  33.  
  34.      k:=k+1;
  35.  
  36.  
  37.      timer1.Enabled:=false;
  38.      end;
  39.     until k=3;
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53. end;
Title: Re: timer delphi
Post by: speter on April 11, 2021, 09:57:14 am
I suggest you have a look at "GetTickCount64".

You can use it to do stuff like:
Code: Pascal  [Select][+][-]
  1. var
  2.   t : QWord;
  3. begin
  4.   t := GetTickCount64;
  5.   // do stuff
  6.   t := GetTickCount64 - t;
  7.   . . .

The function returns a value in milliseconds. In your case you might use GetTickCount64 before the person starts typing then call GetTickCount64 again once they are finished (subtract the two to get the time taken). Use something like "seconds := t div 1000;" to get the seconds taken. If the person is going to take "ages" to complete the task, you could simply get the current time (at the start and end)...

cheers
S. :)
Title: Re: timer delphi
Post by: Handoko on April 11, 2021, 10:18:48 am
Click the link below and go to the section "General". There you can find a "Timer demo".

https://wiki.freepascal.org/Portal:HowTo_Demos
Title: Re: timer delphi
Post by: Mark12345 on April 12, 2021, 01:02:02 am
It says undeclared identifier qword (i'm using delphi 7)
Title: Re: timer delphi
Post by: trev on April 12, 2021, 01:41:35 am
(i'm using delphi 7)

Do you realise you are using the Lazarus and Free Pascal Forum? Maybe you should be using a Delphi Forum.
Title: Re: timer delphi
Post by: speter on April 12, 2021, 01:50:37 am
It says undeclared identifier qword (i'm using delphi 7)
Sadly, I haven't used Delphi 7 for a long long time. It may have a "getTickCount" function.

But, as trev suggests, there may be better forums for you, out there.
I'd suggest doing a search for "Delphi timer" or similar and see where that leads you.

cheers
S.
TinyPortal © 2005-2018