Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 219
  • Last Modified:

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" ?
0
xapsx
Asked:
xapsx
1 Solution
 
esoftbgCommented:
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now