咪
咪咪富翁
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons;
type
sa=class(tthread)
private
protected
procedure execute;override;
end;
TForm1 = class(TForm)
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
procedure SpeedButton2Click(Sender: TObject);
procedure yd(na:tspeedbutton);
procedure SpeedButton3Click(Sender: TObject);
private
{ Private declarations }
public
ywx:sa;
{ Public declarations }
end;
var
Form1: TForm1;
na:tspeedbutton;//申明全局变量
implementation
{$R *.dfm}
procedure tform1.yd(na:tspeedbutton);
//自定义的过程实现单个speedbutton的移动
begin
if na.top>20 then
repeat
na.top:=na.top-1;
until
na.top=20
else
while na.top<200do
na.top:=na.top+1;
end;
procedure sa.execute;
begin
freeonterminate:=true;
//线程结束后自动退出内存
form1.yd(na);
//调用过程
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
na:=speedbutton2;
ywx:=sa.create(false);
//成功移动SpeedButton2,类QQ上的移动
end;
procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
SpeedButton2.Click;//试图先调用SpeedButton2的Click事件同时移动两个
//speedbutton
//问题所在,出现一些奇怪的动作,请指点
na:=speedbutton3;
ywx:=sa.create(false);
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons;
type
sa=class(tthread)
private
protected
procedure execute;override;
end;
TForm1 = class(TForm)
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
procedure SpeedButton2Click(Sender: TObject);
procedure yd(na:tspeedbutton);
procedure SpeedButton3Click(Sender: TObject);
private
{ Private declarations }
public
ywx:sa;
{ Public declarations }
end;
var
Form1: TForm1;
na:tspeedbutton;//申明全局变量
implementation
{$R *.dfm}
procedure tform1.yd(na:tspeedbutton);
//自定义的过程实现单个speedbutton的移动
begin
if na.top>20 then
repeat
na.top:=na.top-1;
until
na.top=20
else
while na.top<200do
na.top:=na.top+1;
end;
procedure sa.execute;
begin
freeonterminate:=true;
//线程结束后自动退出内存
form1.yd(na);
//调用过程
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
na:=speedbutton2;
ywx:=sa.create(false);
//成功移动SpeedButton2,类QQ上的移动
end;
procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
SpeedButton2.Click;//试图先调用SpeedButton2的Click事件同时移动两个
//speedbutton
//问题所在,出现一些奇怪的动作,请指点
na:=speedbutton3;
ywx:=sa.create(false);
end;
end.