我在原form上动态建立了一个form,并在上面建立了一些控件。请问怎么对这些控件添加过程? 如新建一Button那么声明方法procedure MyClick(Sender: TObject);Button.OnClick:=MyClick你看下DFM文件就会明白! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不可能不行!估计你是不知道在哪声明!这样吧,顺你的意Button.OnClick:=Self.MyClick;还有你的方法代码应该是procedure MyClick(Sender: TObject);begin...end;如果是在窗体类中声明的应该是procedure Form1.MyClick(Sender: TObject);begin...end;还要保证参数和控件方法的一致!叫你看看DFM文件中的做法! button.Parent := Form2 ;button.name := "button";button.onclick:= myclick;procedure Form2.MyClick(Sender: TObject);beginShowMessage(ok);end; unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);varbt:tbutton;beginbt:=tbutton.Create(self); with bt do begin parent:=form1; left:=31; top:=21; caption:='sfs'; onclick:=my; end;end;procedure my(Sender: TObject);beginshowmessage('sdf');end;end.错在哪里? 咳!错了!procedure my(Sender: TObject);没声明!unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; procedure my(Sender: TObject);implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);varbt:tbutton;beginbt:=tbutton.Create(self); with bt do begin parent:=form1; left:=31; top:=21; caption:='sfs'; onclick:=my; end;end;procedure my(Sender: TObject);beginshowmessage('sdf');end;end. 或者:unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private procedure my(Sender: TObject); public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);varbt:tbutton;beginbt:=tbutton.Create(self); with bt do begin parent:=form1; left:=31; top:=21; caption:='sfs'; onclick:=my; end;end;procedure TForm1.my(Sender: TObject);beginshowmessage('sdf');end;end. 可以?我的是delphi6.0请把编译通过的代码发到我的信箱里。[email protected]谢谢 请教大家一个问题 用Format('%4s',['a']在'a'前面补上4-1个空格,我想在a的后面补上4-1个空格应该怎么做 天!dbgrid显示出来的字段老长!在设计期把它调短了还是不行,怎么办? char的處理 请问如何获得文件的当前路径? 帮帮忙吧,很急啊!!!请求一个关于判断是否对MonthCalender进行操作的问题 onshow事件什么时候发生? 1.如何锁定计算机....2......十万火急!!!!!!!!! 怎样处理三层结构在中途掉线的问题?急! 谁偷了我的分 这样有什么错啊? 高分请教一简单问题
Button.OnClick:=Self.MyClick;
还有你的方法代码应该是
procedure MyClick(Sender: TObject);
begin
...
end;
如果是在窗体类中声明的
应该是
procedure Form1.MyClick(Sender: TObject);
begin
...
end;
还要保证参数和控件方法的一致!
叫你看看DFM文件中的做法!
button.Parent := Form2 ;
button.name := "button";
button.onclick:= myclick;procedure Form2.MyClick(Sender: TObject);
begin
ShowMessage(ok);
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
bt:tbutton;
begin
bt:=tbutton.Create(self);
with bt do
begin
parent:=form1;
left:=31;
top:=21;
caption:='sfs';
onclick:=my;
end;
end;procedure my(Sender: TObject);
begin
showmessage('sdf');
end;end.
错在哪里?
procedure my(Sender: TObject);没声明!unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
procedure my(Sender: TObject);implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
bt:tbutton;
begin
bt:=tbutton.Create(self);
with bt do
begin
parent:=form1;
left:=31;
top:=21;
caption:='sfs';
onclick:=my;
end;
end;procedure my(Sender: TObject);
begin
showmessage('sdf');
end;end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
procedure my(Sender: TObject);
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
bt:tbutton;
begin
bt:=tbutton.Create(self);
with bt do
begin
parent:=form1;
left:=31;
top:=21;
caption:='sfs';
onclick:=my;
end;
end;procedure TForm1.my(Sender: TObject);
begin
showmessage('sdf');
end;end.
我的是delphi6.0
请把编译通过的代码发到我的信箱里。
[email protected]
谢谢