integer to string problems

sec := 12;

procedure TForm1.countsecTimer(Sender: TObject);
var
sec : integer;
begin
  sec := sec -1 ;
Label3.Caption :=  IntToStr (sec) + ' Sec';
end;
---------------------------------


hmm why if i write -- sec := sec -1 -- , label3 will be : "4432467" and if i write --- sec := 12 -1 , "label3 = 11" ?
xapsxAsked:
Who is Participating?
 
esoftbgConnect With a Mentor Commented:
It is incorrect to use a local variable into the countsecTimer() method ....
Please declare the Sec variable this way:

type
  TForm1 = class(TForm)
      Button1: TButton;
      countsec: TTimer;
      Label3: TLabel;
      procedure Button1Click(Sender: TObject);
      procedure countsecTimer(Sender: TObject);
    private
    { Private declarations }
    public
      Sec:    Integer;
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Sec := 12; // you may change the value of the global Sec variable
end;

procedure TForm1.countsecTimer(Sender: TObject);
begin
  Sec := Sec - 1;
  Label3.Caption :=  IntToStr (Sec) + ' Sec';
end;

end.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.