T
tmcco
Unregistered / Unconfirmed
GUEST, unregistred user!
OnClick事件正常,但SpeedButton1的事件则引发“Invalid class typecast"
似乎和Sender有关,但不知如何改,请赐教!!
原程如下:(有删节)
type
TForm1 = class(TForm)
SpeedButton1: TSpeedButton;
procedure FormCreate(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
private
procedure xx(Sender: TObject);
public
end;
var
Form1: TForm1;
alarmButton:array of TButton;
i,j:integer;
implementation
{$R *.dfm}
procedure TForm1.xx(Sender: TObject);
begin
ShowMessage(IntToStr((Sender as TButton).Top));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
for i := 0 to 9 do
begin
SetLength(alarmButton, i +1);
alarmButton := TButton.Create(Form1);
alarmButton.Parent := Form1;
alarmButton.Top := 50 + i * 30;
alarmButton.Left := 50 + i * 50;
alarmButton.Caption := 'asdasd';
alarmButton.OnClick:= xx;
alarmButton.Show;
end;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
//目的是改变10个Button中的Caption
for i:= 0 to 9 do
begin
alarmButton.Caption:= 'qwe';
end;
end;
end.
似乎和Sender有关,但不知如何改,请赐教!!
原程如下:(有删节)
type
TForm1 = class(TForm)
SpeedButton1: TSpeedButton;
procedure FormCreate(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
private
procedure xx(Sender: TObject);
public
end;
var
Form1: TForm1;
alarmButton:array of TButton;
i,j:integer;
implementation
{$R *.dfm}
procedure TForm1.xx(Sender: TObject);
begin
ShowMessage(IntToStr((Sender as TButton).Top));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
for i := 0 to 9 do
begin
SetLength(alarmButton, i +1);
alarmButton := TButton.Create(Form1);
alarmButton.Parent := Form1;
alarmButton.Top := 50 + i * 30;
alarmButton.Left := 50 + i * 50;
alarmButton.Caption := 'asdasd';
alarmButton.OnClick:= xx;
alarmButton.Show;
end;
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
//目的是改变10个Button中的Caption
for i:= 0 to 9 do
begin
alarmButton.Caption:= 'qwe';
end;
end;
end.