这个代码那里出了错误呀???

li3807 2003-09-14 09:29:29
unit Unit1;

interface

uses
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.
...全文
30 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
killme2008 2003-09-15
  • 打赏
  • 举报
回复
按gx(gx)运行没错!!
qiume 2003-09-15
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
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.
zousoft 2003-09-14
  • 打赏
  • 举报
回复

procedure TForm1.ButtonAllClick(sender:Tobject);
begin
application.MessageBox(TButton(sender).caption,'对话框',MB_OK);
end;

放到implementation后面去。
li3807 2003-09-14
  • 打赏
  • 举报
回复
[Error] Unit1.pas(21): Identifier redeclared: 'TForm1.ButtonAllClick'
[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
gx 2003-09-14
  • 打赏
  • 举报
回复
请注意以下代码的位置和Pchar()转化函数:
procedure TForm1.ButtonAllClick(sender:Tobject);
begin
application.MessageBox(TButton(sender).caption,'对话框',MB_OK);
end;


----------------------------------

unit Unit1;

interface

uses
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.
lxpbuaa 2003-09-14
  • 打赏
  • 举报
回复
application.MessageBox(TButton(sender).caption,'对话框',MB_OK);
改为:
application.MessageBox(PChar(TButton(sender).caption), '对话框', MB_OK);

—————————————————————————————————
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
—————————————————————————————————

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧