Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateTime initialization

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Why this code cause this message:

[Warning] Unit1.pas(32): Variable 'Time' might not have been initialized:

procedure TForm1.Timer1Timer(Sender: TObject);
var
Time : TDateTime;
str : string;
begin
Time := Time;
str := TimeToStr(Time);
Label1.Caption := str;
end;

end.
 
You are using a variable Time and the reserved function time together. The compiler is getting confused.

Do not use variables with the same names as reserved words, it can screw up your program, or computer.

Regards
S. van Els
SAvanEls@cq-link.sr
 
You may want to try this...

procedure TForm1.Timer1Timer(Sender: TObject);
var
begin
Label1.Caption := FormatDateTime('HH:MM:NN', Now);
end;

Paul Wesson
paul@wessoft.com
 
you may also want to try this...

Drop a "Timer" and a "Label" on the Form and add the following code to the the Timer's "On Timer" Event

procedure TForm1.Timer1Timer(Sender:TObject);
begin
Label1.Caption:=timetostr(now);
end;


have fun!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top