Delphi and Kylix

Moderators: pritaeas
Number of threads: 7264
Number of posts: 19073

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
current time - old time problem Posted by porodoro on 25 May 2006 at 4:21 AM
This message was edited by porodoro at 2006-5-25 4:22:31

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?


Report
Re: current time - old time problem Posted by zibadian on 25 May 2006 at 3:59 PM
: This message was edited by porodoro at 2006-5-25 4:22:31

: 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.
Report
Re: current time - old time problem Posted by porodoro on 26 May 2006 at 3:40 AM
: : This message was edited by porodoro at 2006-5-25 4:22:31

: : 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)
Report
Re: current time - old time problem Posted by porodoro on 26 May 2006 at 4:01 AM
: : : This message was edited by porodoro at 2006-5-25 4:22:31

: : : 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())"

Report
Re: current time - old time problem Posted by zibadian on 26 May 2006 at 6:23 AM
: : : : This message was edited by porodoro at 2006-5-25 4:22:31

: : : : 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.
Report
Re: current time - old time problem Posted by porodoro on 26 May 2006 at 7:51 AM
This message was edited by porodoro at 2006-5-26 7:55:26

This message was edited by porodoro at 2006-5-26 7:54:31

: : : : : This message was edited by porodoro at 2006-5-25 4:22:31

: : : : : 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?




Report
Re: current time - old time problem Posted by zibadian on 26 May 2006 at 8:04 AM
: This message was edited by porodoro at 2006-5-26 7:55:26

: This message was edited by porodoro at 2006-5-26 7:54:31

: : : : : : This message was edited by porodoro at 2006-5-25 4:22:31

: : : : : : 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:
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;

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.
Report
Re: current time - old time problem Posted by porodoro on 26 May 2006 at 8:22 AM
: : This message was edited by porodoro at 2006-5-26 7:55:26

: : This message was edited by porodoro at 2006-5-26 7:54:31

: : : : : : : This message was edited by porodoro at 2006-5-25 4:22:31

: : : : : : : 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:
:
: 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;
: 

: 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
Report
Re: current time - old time problem Posted by zibadian on 26 May 2006 at 8:34 AM
: : : This message was edited by porodoro at 2006-5-26 7:55:26

: : : This message was edited by porodoro at 2006-5-26 7:54:31

: : : : : : : : This message was edited by porodoro at 2006-5-25 4:22:31

: : : : : : : : 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:
: :
: : 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;
: : 

: : 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.
Report
Re: current time - old time problem Posted by porodoro on 26 May 2006 at 8:54 AM
This message was edited by porodoro at 2006-5-26 8:59:9

This message was edited by porodoro at 2006-5-26 8:55:17

: : : : This message was edited by porodoro at 2006-5-26 7:55:26

: : : : This message was edited by porodoro at 2006-5-26 7:54:31

: : : : : : : : : This message was edited by porodoro at 2006-5-25 4:22:31

: : : : : : : : : 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:
: : :
: : : 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;
: : : 

: : : 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);"









 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.