[b][red]This message was edited by porodoro at 2006-5-25 4:22:31[/red][/b][hr]
I have this code :
global variable
GetTIME: ttime;
On create
gettime := now;
on button click code
var x :Ttime;
var s :string;
x:=now;
S:='Time past till last run';
showmessage(S+':'+timetostr(x-gettime) );
But it doesnt show the time past properly..why?
Comments
: I have this code :
:
:
: global variable
:
: GetTIME: ttime;
:
: On create
: gettime := now;
:
: on button click code
:
: var x :Ttime;
: var s :string;
:
: x:=now;
: S:='Time past till last run';
:
: showmessage(S+':'+timetostr(x-gettime) );
:
: But it doesnt show the time past properly..why?
:
:
:
GetTime might also be a function name. It now shows only the time difference from the beginning of the program (OnCreate()) till the user clicks the button (OnClick()), not from the time the program last ran before this time.
: : I have this code :
: :
: :
: : global variable
: :
: : GetTIME: ttime;
: :
: : On create
: : gettime := now;
: :
: : on button click code
: :
: : var x :Ttime;
: : var s :string;
: :
: : x:=now;
: : S:='Time past till last run';
: :
: : showmessage(S+':'+timetostr(x-gettime) );
: :
: : But it doesnt show the time past properly..why?
: :
: :
: :
: GetTime might also be a function name. It now shows only the time difference from the beginning of the program (OnCreate()) till the user clicks the button (OnClick()), not from the time the program last ran before this time.
:
Is there any better solution ? (timer eg)
: : : I have this code :
: : :
: : :
: : : global variable
: : :
: : : GetTIME: ttime;
: : :
: : : On create
: : : gettime := now;
: : :
: : : on button click code
: : :
: : : var x :Ttime;
: : : var s :string;
: : :
: : : x:=now;
: : : S:='Time past till last run';
: : :
: : : showmessage(S+':'+timetostr(x-gettime) );
: : :
: : : But it doesnt show the time past properly..why?
: : :
: : :
: : :
: : GetTime might also be a function name. It now shows only the time difference from the beginning of the program (OnCreate()) till the user clicks the button (OnClick()), not from the time the program last ran before this time.
: :
: Is there any better solution ? (timer eg)
:
Sorry , miss understanding.
I meant this :
[b]"It now shows only the time difference from the beginning of the program (OnCreate()) till the user clicks the button (OnClick())"[b]
: : : : I have this code :
: : : :
: : : :
: : : : global variable
: : : :
: : : : GetTIME: ttime;
: : : :
: : : : On create
: : : : gettime := now;
: : : :
: : : : on button click code
: : : :
: : : : var x :Ttime;
: : : : var s :string;
: : : :
: : : : x:=now;
: : : : S:='Time past till last run';
: : : :
: : : : showmessage(S+':'+timetostr(x-gettime) );
: : : :
: : : : But it doesnt show the time past properly..why?
: : : :
: : : :
: : : :
: : : GetTime might also be a function name. It now shows only the time difference from the beginning of the program (OnCreate()) till the user clicks the button (OnClick()), not from the time the program last ran before this time.
: : :
: : Is there any better solution ? (timer eg)
: :
: Sorry , miss understanding.
: I meant this :
: [b]"It now shows only the time difference from the beginning of the program (OnCreate()) till the user clicks the button (OnClick())"[b]
:
:
It's unclear to me what you want to do. Hence I explained what your code does.
[b][red]This message was edited by porodoro at 2006-5-26 7:54:31[/red][/b][hr]
: : : : : [b][red]This message was edited by porodoro at 2006-5-25 4:22:31[/red][/b][hr]
: : : : : I have this code :
: : : : :
: : : : :
: : : : : global variable
: : : : :
: : : : : GetTIME: ttime;
: : : : :
: : : : : On create
: : : : : gettime := now;
: : : : :
: : : : : on button click code
: : : : :
: : : : : var x :Ttime;
: : : : : var s :string;
: : : : :
: : : : : x:=now;
: : : : : S:='Time past till last run';
: : : : :
: : : : : showmessage(S+':'+timetostr(x-gettime) );
: : : : :
: : : : : But it doesnt show the time past properly..why?
: : : : :
: : : : :
: : : : :
: : : : GetTime might also be a function name. It now shows only the time difference from the beginning of the program (OnCreate()) till the user clicks the button (OnClick()), not from the time the program last ran before this time.
: : : :
: : : Is there any better solution ? (timer eg)
: : :
: : Sorry , miss understanding.
: : I meant this :
: : [b]"It now shows only the time difference from the beginning of the program (OnCreate()) till the user clicks the button (OnClick())"[b]
: :
: :
: It's unclear to me what you want to do. Hence I explained what your code does.
:
I just need to calculate the time difference from the start untill the user clicks the button.
I changed GetTIME to _GetTIME_ but still it doesnt show the difference
in mins & secs.
Why?
------------
Also i've tryed with timer but the calculations are buggy.
Here's what i did:
global:
Count_:integer;
reset_count:integer;
(on form create)
Count_:=0;
reset_count :=0;
timer1.interval := 1000;
(on timer event)
Count_ := Count_+1;
if (Count_ >=60) then reset_count:=reset_count+1;
if (count_ >65535) then Count_:=0;
(on button click)
if (reset_count <1) then
Showmessage('less than minute')
else
ShowmessagE(INTtoStr(reset_count));
You think this wont cause any trouble?
: [b][red]This message was edited by porodoro at 2006-5-26 7:54:31[/red][/b][hr]
: : : : : : [b][red]This message was edited by porodoro at 2006-5-25 4:22:31[/red][/b][hr]
: : : : : : I have this code :
: : : : : :
: : : : : :
: : : : : : global variable
: : : : : :
: : : : : : GetTIME: ttime;
: : : : : :
: : : : : : On create
: : : : : : gettime := now;
: : : : : :
: : : : : : on button click code
: : : : : :
: : : : : : var x :Ttime;
: : : : : : var s :string;
: : : : : :
: : : : : : x:=now;
: : : : : : S:='Time past till last run';
: : : : : :
: : : : : : showmessage(S+':'+timetostr(x-gettime) );
: : : : : :
: : : : : : But it doesnt show the time past properly..why?
: : : : : :
: : : : : :
: : : : : :
: : : : : GetTime might also be a function name. It now shows only the time difference from the beginning of the program (OnCreate()) till the user clicks the button (OnClick()), not from the time the program last ran before this time.
: : : : :
: : : : Is there any better solution ? (timer eg)
: : : :
: : : Sorry , miss understanding.
: : : I meant this :
: : : [b]"It now shows only the time difference from the beginning of the program (OnCreate()) till the user clicks the button (OnClick())"[b]
: : :
: : :
: : It's unclear to me what you want to do. Hence I explained what your code does.
: :
: I just need to calculate the time difference from the start untill the user clicks the button.
:
: I changed GetTIME to _GetTIME_ but still it doesnt show the difference
: in mins & secs.
: Why?
:
: ------------
: Also i've tryed with timer but the calculations are buggy.
:
: Here's what i did:
:
: global:
: Count_:integer;
: reset_count:integer;
: (on form create)
: Count_:=0;
: reset_count :=0;
: timer1.interval := 1000;
:
: (on timer event)
: Count_ := Count_+1;
: if (Count_ >=60) then reset_count:=reset_count+1;
: if (count_ >65535) then Count_:=0;
:
: (on button click)
: if (reset_count <1) then
: Showmessage('less than minute')
: else
: ShowmessagE(INTtoStr(reset_count));
:
: You think this wont cause any trouble?
:
:
:
:
: [/b]
I've tested your original code, and it works perfectly. Here's my test code:
[code]
type
TForm1 = class(TForm)
Label1: TLabel;
Button3: TButton;
procedure FormCreate(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
F: TTime;
public
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
F := Now;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Label1.Caption := TimeToStr(Now-F);
end;
[/code]
When I click shortly after starting the program it shows 0 mins and 2 sec. And after waiting quite a while, it showed 1 min and 10 sec., which is correct according to my watch.
: : [b][red]This message was edited by porodoro at 2006-5-26 7:54:31[/red][/b][hr]
: : : : : : : [b][red]This message was edited by porodoro at 2006-5-25 4:22:31[/red][/b][hr]
: : : : : : : I have this code :
: : : : : : :
: : : : : : :
: : : : : : : global variable
: : : : : : :
: : : : : : : GetTIME: ttime;
: : : : : : :
: : : : : : : On create
: : : : : : : gettime := now;
: : : : : : :
: : : : : : : on button click code
: : : : : : :
: : : : : : : var x :Ttime;
: : : : : : : var s :string;
: : : : : : :
: : : : : : : x:=now;
: : : : : : : S:='Time past till last run';
: : : : : : :
: : : : : : : showmessage(S+':'+timetostr(x-gettime) );
: : : : : : :
: : : : : : : But it doesnt show the time past properly..why?
: : : : : : :
: : : : : : :
: : : : : : :
: : : : : : GetTime might also be a function name. It now shows only the time difference from the beginning of the program (OnCreate()) till the user clicks the button (OnClick()), not from the time the program last ran before this time.
: : : : : :
: : : : : Is there any better solution ? (timer eg)
: : : : :
: : : : Sorry , miss understanding.
: : : : I meant this :
: : : : [b]"It now shows only the time difference from the beginning of the program (OnCreate()) till the user clicks the button (OnClick())"[b]
: : : :
: : : :
: : : It's unclear to me what you want to do. Hence I explained what your code does.
: : :
: : I just need to calculate the time difference from the start untill the user clicks the button.
: :
: : I changed GetTIME to _GetTIME_ but still it doesnt show the difference
: : in mins & secs.
: : Why?
: :
: : ------------
: : Also i've tryed with timer but the calculations are buggy.
: :
: : Here's what i did:
: :
: : global:
: : Count_:integer;
: : reset_count:integer;
: : (on form create)
: : Count_:=0;
: : reset_count :=0;
: : timer1.interval := 1000;
: :
: : (on timer event)
: : Count_ := Count_+1;
: : if (Count_ >=60) then reset_count:=reset_count+1;
: : if (count_ >65535) then Count_:=0;
: :
: : (on button click)
: : if (reset_count <1) then
: : Showmessage('less than minute')
: : else
: : ShowmessagE(INTtoStr(reset_count));
: :
: : You think this wont cause any trouble?
: :
: :
: :
: :
: : [/b]
: I've tested your original code, and it works perfectly. Here's my test code:
: [code]
: type
: TForm1 = class(TForm)
: Label1: TLabel;
: Button3: TButton;
: procedure FormCreate(Sender: TObject);
: procedure Button3Click(Sender: TObject);
: private
: F: TTime;
: public
: end;
:
: procedure TForm1.FormCreate(Sender: TObject);
: begin
: F := Now;
: end;
:
: procedure TForm1.Button3Click(Sender: TObject);
: begin
: Label1.Caption := TimeToStr(Now-F);
: end;
: [/code]
: When I click shortly after starting the program it shows 0 mins and 2 sec. And after waiting quite a while, it showed 1 min and 10 sec., which is correct according to my watch.
:
And how to remove this (plz take a look at the screenshot):
http://tinypic.com/10qdtsj.jpg
: : : [b][red]This message was edited by porodoro at 2006-5-26 7:54:31[/red][/b][hr]
: : : : : : : : [b][red]This message was edited by porodoro at 2006-5-25 4:22:31[/red][/b][hr]
: : : : : : : : I have this code :
: : : : : : : :
: : : : : : : :
: : : : : : : : global variable
: : : : : : : :
: : : : : : : : GetTIME: ttime;
: : : : : : : :
: : : : : : : : On create
: : : : : : : : gettime := now;
: : : : : : : :
: : : : : : : : on button click code
: : : : : : : :
: : : : : : : : var x :Ttime;
: : : : : : : : var s :string;
: : : : : : : :
: : : : : : : : x:=now;
: : : : : : : : S:='Time past till last run';
: : : : : : : :
: : : : : : : : showmessage(S+':'+timetostr(x-gettime) );
: : : : : : : :
: : : : : : : : But it doesnt show the time past properly..why?
: : : : : : : :
: : : : : : : :
: : : : : : : :
: : : : : : : GetTime might also be a function name. It now shows only the time difference from the beginning of the program (OnCreate()) till the user clicks the button (OnClick()), not from the time the program last ran before this time.
: : : : : : :
: : : : : : Is there any better solution ? (timer eg)
: : : : : :
: : : : : Sorry , miss understanding.
: : : : : I meant this :
: : : : : "It now shows only the time difference from the beginning of the program (OnCreate()) till the user clicks the button (OnClick())"
: : : : :
: : : : :
: : : : It's unclear to me what you want to do. Hence I explained what your code does.
: : : :
: : : I just need to calculate the time difference from the start untill the user clicks the button.
: : :
: : : I changed GetTIME to _GetTIME_ but still it doesnt show the difference
: : : in mins & secs.
: : : Why?
: : :
: : : ------------
: : : Also i've tryed with timer but the calculations are buggy.
: : :
: : : Here's what i did:
: : :
: : : global:
: : : Count_:integer;
: : : reset_count:integer;
: : : (on form create)
: : : Count_:=0;
: : : reset_count :=0;
: : : timer1.interval := 1000;
: : :
: : : (on timer event)
: : : Count_ := Count_+1;
: : : if (Count_ >=60) then reset_count:=reset_count+1;
: : : if (count_ >65535) then Count_:=0;
: : :
: : : (on button click)
: : : if (reset_count <1) then
: : : Showmessage('less than minute')
: : : else
: : : ShowmessagE(INTtoStr(reset_count));
: : :
: : : You think this wont cause any trouble?
: : :
: : :
: : :
: : :
: : :
: : I've tested your original code, and it works perfectly. Here's my test code:
: : [code]
: : type
: : TForm1 = class(TForm)
: : Label1: TLabel;
: : Button3: TButton;
: : procedure FormCreate(Sender: TObject);
: : procedure Button3Click(Sender: TObject);
: : private
: : F: TTime;
: : public
: : end;
: :
: : procedure TForm1.FormCreate(Sender: TObject);
: : begin
: : F := Now;
: : end;
: :
: : procedure TForm1.Button3Click(Sender: TObject);
: : begin
: : Label1.Caption := TimeToStr(Now-F);
: : end;
: : [/code]
: : When I click shortly after starting the program it shows 0 mins and 2 sec. And after waiting quite a while, it showed 1 min and 10 sec., which is correct according to my watch.
: :
: And how to remove this (plz take a look at the screenshot):
: http://tinypic.com/10qdtsj.jpg
:
I don't know. Perhaps you should use a TDateTime variable instead of a TTime. It could be because of the day(or day-half in 12 hour setting) switch. Another solution would be to use FormatDateTime() instead of TimeToStr(). That function gives you more control over the appearance of the time.
[b][red]This message was edited by porodoro at 2006-5-26 8:55:17[/red][/b][hr]
: : : : [b][red]This message was edited by porodoro at 2006-5-26 7:55:26[/red][/b][hr]
: : : : [b][red]This message was edited by porodoro at 2006-5-26 7:54:31[/red][/b][hr]
: : : : : : : : : [b][red]This message was edited by porodoro at 2006-5-25 4:22:31[/red][/b][hr]
: : : : : : : : : I have this code :
: : : : : : : : :
: : : : : : : : :
: : : : : : : : : global variable
: : : : : : : : :
: : : : : : : : : GetTIME: ttime;
: : : : : : : : :
: : : : : : : : : On create
: : : : : : : : : gettime := now;
: : : : : : : : :
: : : : : : : : : on button click code
: : : : : : : : :
: : : : : : : : : var x :Ttime;
: : : : : : : : : var s :string;
: : : : : : : : :
: : : : : : : : : x:=now;
: : : : : : : : : S:='Time past till last run';
: : : : : : : : :
: : : : : : : : : showmessage(S+':'+timetostr(x-gettime) );
: : : : : : : : :
: : : : : : : : : But it doesnt show the time past properly..why?
: : : : : : : : :
: : : : : : : : :
: : : : : : : : :
: : : : : : : : GetTime might also be a function name. It now shows only the time difference from the beginning of the program (OnCreate()) till the user clicks the button (OnClick()), not from the time the program last ran before this time.
: : : : : : : :
: : : : : : : Is there any better solution ? (timer eg)
: : : : : : :
: : : : : : Sorry , miss understanding.
: : : : : : I meant this :
: : : : : : "It now shows only the time difference from the beginning of the program (OnCreate()) till the user clicks the button (OnClick())"
: : : : : :
: : : : : :
: : : : : It's unclear to me what you want to do. Hence I explained what your code does.
: : : : :
: : : : I just need to calculate the time difference from the start untill the user clicks the button.
: : : :
: : : : I changed GetTIME to _GetTIME_ but still it doesnt show the difference
: : : : in mins & secs.
: : : : Why?
: : : :
: : : : ------------
: : : : Also i've tryed with timer but the calculations are buggy.
: : : :
: : : : Here's what i did:
: : : :
: : : : global:
: : : : Count_:integer;
: : : : reset_count:integer;
: : : : (on form create)
: : : : Count_:=0;
: : : : reset_count :=0;
: : : : timer1.interval := 1000;
: : : :
: : : : (on timer event)
: : : : Count_ := Count_+1;
: : : : if (Count_ >=60) then reset_count:=reset_count+1;
: : : : if (count_ >65535) then Count_:=0;
: : : :
: : : : (on button click)
: : : : if (reset_count <1) then
: : : : Showmessage('less than minute')
: : : : else
: : : : ShowmessagE(INTtoStr(reset_count));
: : : :
: : : : You think this wont cause any trouble?
: : : :
: : : :
: : : :
: : : :
: : : :
: : : I've tested your original code, and it works perfectly. Here's my test code:
: : : [code]
: : : type
: : : TForm1 = class(TForm)
: : : Label1: TLabel;
: : : Button3: TButton;
: : : procedure FormCreate(Sender: TObject);
: : : procedure Button3Click(Sender: TObject);
: : : private
: : : F: TTime;
: : : public
: : : end;
: : :
: : : procedure TForm1.FormCreate(Sender: TObject);
: : : begin
: : : F := Now;
: : : end;
: : :
: : : procedure TForm1.Button3Click(Sender: TObject);
: : : begin
: : : Label1.Caption := TimeToStr(Now-F);
: : : end;
: : : [/code]
: : : When I click shortly after starting the program it shows 0 mins and 2 sec. And after waiting quite a while, it showed 1 min and 10 sec., which is correct according to my watch.
: : :
: : And how to remove this (plz take a look at the screenshot):
: : http://tinypic.com/10qdtsj.jpg
: :
: I don't know. Perhaps you should use a TDateTime variable instead of a TTime. It could be because of the day(or day-half in 12 hour setting) switch. Another solution would be to use FormatDateTime() instead of TimeToStr(). That function gives you more control over the appearance of the time.
:
Thanks zibadian , for one more time i solved my noobish problem.
What i did :
(d is a global variable that holds the time on create event)
in case we want just seconds
for minutes just remove "ss" & add nn.
"FormatDateTime('" " ss',d-now);"