delphi7怎样实现按下一个按钮程序自动按顺序每500ms执行一项修改Edit.Text值,有多个需修改项目。
例如我就3个edit控件,我要把3个字符串str1,str2,str3按顺序填入edit1,edit2,edit3,修改到edit3后停止,修改操作间隔500ms执行...
例如我就3个edit控件,我要把3个字符串str1,str2,str3按顺序填入edit1,edit2,edit3,修改到edit3后停止,修改操作间隔500ms执行
展开
展开全部
加入一个时间控件Ttimer1,其enabled属性设置为false。在你需要程序自动按顺序每500ms执行一次时,把interval属性设置为500,同时把enabled属性设置为true。你需要它结束时把enabled设置为false
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Timer1: TTimer;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Timer2: TTimer;
Button2: TButton;
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
str1,str2,str3:string;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
edit1.Text:=str1;
edit2.Text:=str2;
edit3.Text:=str3;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
begin
str1:=inttostr(random(10000));
str2:=inttostr(random(10000));
str3:=inttostr(random(10000));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Timer2.Enabled:=true;
Timer1.Enabled:=true;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Timer1.Enabled:=false;
Timer2.Enabled:=false;
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Timer1: TTimer;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Timer2: TTimer;
Button2: TButton;
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
str1,str2,str3:string;
implementation
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject);
begin
edit1.Text:=str1;
edit2.Text:=str2;
edit3.Text:=str3;
end;
procedure TForm1.Timer2Timer(Sender: TObject);
begin
str1:=inttostr(random(10000));
str2:=inttostr(random(10000));
str3:=inttostr(random(10000));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Timer2.Enabled:=true;
Timer1.Enabled:=true;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Timer1.Enabled:=false;
Timer2.Enabled:=false;
end;
end.
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Edit1.text:=str1;
sleep(500);
edit2.text:=str2;
sleep(500);
edit3.Text:=Str3;
sleep(500);
edit2.text:=str2;
sleep(500);
edit3.Text:=Str3;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
procedure Delay(dwMilliseconds: DWORD); //Longint
var
iStart, iStop: DWORD;
begin
iStart := GetTickCount;
repeat
iStop := GetTickCount;
Application.ProcessMessages;
until (iStop - iStart) >= dwMilliseconds;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
T:Tedit;
begin
for i := 1 to 3 do
begin
T:=Findcomponent('Edit'+inttostr(i)) as TEdit;
if T<>nil then T.Text:='str'+inttostr(i);
delay(500);
end;
ShowMessage('OK');
end;
var
iStart, iStop: DWORD;
begin
iStart := GetTickCount;
repeat
iStop := GetTickCount;
Application.ProcessMessages;
until (iStop - iStart) >= dwMilliseconds;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
T:Tedit;
begin
for i := 1 to 3 do
begin
T:=Findcomponent('Edit'+inttostr(i)) as TEdit;
if T<>nil then T.Text:='str'+inttostr(i);
delay(500);
end;
ShowMessage('OK');
end;
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Timer1的interval:=500
'Timer1里面的事件:
begin
Edit1.text:=str1;
edit2.text:=str2;
edit3.Text:=Str3;
end;
'Timer1里面的事件:
begin
Edit1.text:=str1;
edit2.text:=str2;
edit3.Text:=Str3;
end;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询