如何在DELPHI中 自动重复按Button1?

来源:百度知道 编辑:UC知道 时间:2024/06/30 09:33:24
如何实现?还要可以设置时间间隔。。 就是 。每隔多少秒。自动按 BUTTON1。就算程序最小化了。也不影响。

分不多。。希望能得到帮助。谢谢。

【步骤】从选项卡上拖1个label,1个button,1个timer到窗体上,让后分别在button的onclick事件,和timer的timer事件写如下代码:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;

type
TForm1 = class(TForm)
Timer1: TTimer;
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
begin
//这里写click执行代码
i := StrToInt(TimeToStr(time)[Length(TimeToStr(time))]);
if (i mod 2) = 1 then
label1.Caption := 'Button1Click执行了奇数次'
else
label1.Caption := 'Button1Click执行