unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
private
abutton:array [1..100] of TButton;
procedure ButtonAllClick(sender:Tobject);
public
{ Public declarations }
end; procedure TForm1.ButtonAllClick(sender:Tobject);
begin
application.MessageBox(TButton(sender).caption,'对话框',MB_OK);
end;
var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.BitBtn1Click(Sender: TObject);
var
i,j:integer;
begin
for i:=0 to 9 do
begin
for j:=1 to 10 do
begin
abutton[i*10+j]:=Tbutton.Create(self);
abutton[i*10+j].Parent:=Self;
abutton[i*10+j].Width:=100;
abutton[i*10+j].Height:=30;
abutton[i*10+j].Left:=i*abutton[i*10+j].Width+20;
abutton[i*10+j].Top:=j*abutton[i*10+j].Height+20;
abutton[i*10+j].Caption:=inttostr(i*10+j);
abutton[i*10+j].OnClick:=ButtonAllClick;
end;
end;
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
private
abutton:array [1..100] of TButton;
procedure ButtonAllClick(sender:Tobject);
public
{ Public declarations }
end; procedure TForm1.ButtonAllClick(sender:Tobject);
begin
application.MessageBox(TButton(sender).caption,'对话框',MB_OK);
end;
var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.BitBtn1Click(Sender: TObject);
var
i,j:integer;
begin
for i:=0 to 9 do
begin
for j:=1 to 10 do
begin
abutton[i*10+j]:=Tbutton.Create(self);
abutton[i*10+j].Parent:=Self;
abutton[i*10+j].Width:=100;
abutton[i*10+j].Height:=30;
abutton[i*10+j].Left:=i*abutton[i*10+j].Width+20;
abutton[i*10+j].Top:=j*abutton[i*10+j].Height+20;
abutton[i*10+j].Caption:=inttostr(i*10+j);
abutton[i*10+j].OnClick:=ButtonAllClick;
end;
end;
end;end.
改为:
application.MessageBox(PChar(TButton(sender).caption), '对话框', MB_OK);—————————————————————————————————
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
—————————————————————————————————
procedure TForm1.ButtonAllClick(sender:Tobject);
begin
application.MessageBox(TButton(sender).caption,'对话框',MB_OK);
end;
----------------------------------unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
private
abutton:array [1..100] of TButton;
procedure ButtonAllClick(sender:Tobject);
public
{ Public declarations }
end;
var
Form1: TForm1;implementation{$R *.dfm}
procedure TForm1.ButtonAllClick(sender:Tobject);
begin
application.MessageBox(Pchar(TButton(sender).caption),'对话框',MB_OK);
end;procedure TForm1.BitBtn1Click(Sender: TObject);
var
i,j:integer;
begin
for i:=0 to 9 do
begin
for j:=1 to 10 do
begin
abutton[i*10+j]:=Tbutton.Create(self);
abutton[i*10+j].Parent:=Self;
abutton[i*10+j].Width:=100;
abutton[i*10+j].Height:=30;
abutton[i*10+j].Left:=i*abutton[i*10+j].Width+20;
abutton[i*10+j].Top:=j*abutton[i*10+j].Height+20;
abutton[i*10+j].Caption:=inttostr(i*10+j);
abutton[i*10+j].OnClick:=ButtonAllClick;
end;
end;
end;end.
[Error] Unit1.pas(22): Undeclared identifier: 'sender'
[Error] Unit1.pas(15): Unsatisfied forward or external declaration: 'TForm1.ButtonAllClick'
[Fatal Error] Project1.dpr(5): Could not compile used unit 'Unit1.pas'
还是出这个错误,我用的是Delphi7.0
procedure TForm1.ButtonAllClick(sender:Tobject);
begin
application.MessageBox(TButton(sender).caption,'对话框',MB_OK);
end;放到implementation后面去。
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
private
abutton:array [1..100] of TButton;
procedure ButtonAllClick(sender:Tobject);
public
{ Public declarations }
end;
var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.BitBtn1Click(Sender: TObject);
var
i,j:integer;
begin
for i:=0 to 9 do
begin
for j:=1 to 10 do
begin
abutton[i*10+j]:=Tbutton.Create(self);
abutton[i*10+j].Parent:=Self;
abutton[i*10+j].Width:=100;
abutton[i*10+j].Height:=30;
abutton[i*10+j].Left:=i*abutton[i*10+j].Width+20;
abutton[i*10+j].Top:=j*abutton[i*10+j].Height+20;
abutton[i*10+j].Caption:=inttostr(i*10+j);
abutton[i*10+j].OnClick:=ButtonAllClick;
end;
end;
end;procedure TForm1.ButtonAllClick(Sender: Tobject);
begin
Application.MessageBox(PChar(TButton(Sender).Caption),'对话框',MB_OK);
end;end.