菜鸟求助!
窗体上一个Timmer,一个Edit1。代码如下,这样运行edit1中的数会不断增长,1,2,3。。。。怎样就让i:=i+1就执行一次?也就是Edit1中只为1?前提是必须在timmer事件中。多谢!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Timer1: TTimer;
Edit1: TEdit;
procedure Timer1Timer(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
abc:bool;
i:integer;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if abc then
begin
i:=i+1;
Edit1.Text:=inttostr(i);
end;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
i:=0;
abc:=true;
end;
end.
[解决办法]
if abc then
begin
TTimer(Sender).Enabled := False;
i:=i+1;
Edit1.Text:=inttostr(i);
end;