procedure myProc(sender: tobject); begin if sender is tbutton then ShowMessage(inttostr((sender as tbutton).tag))); end; 可以这样 with btn[1] do begin Tag:=1; OnClick:=MyProc; end;....
var Form1: TForm1; btn:array[0..9] of TButton;var i:Integer;begin for i := 0 to 9 do begin btn[i]:=TButton.Create(Self); with btn[i] do begin Top:=30*i; Left:=0; Show; OnClick:=ButtonClick; end; end; end;procedure TForm.ButtonClick(Sender:TObject) begin if (Sender as TButton)=btn[0] then ... else (Sender as TButton)=btn[1] then ... ... end;
我做考试系统时做过,思路可以是这样: for ( 从i:=0开始到用户填的数) begin new 生成checkbox 每个的区别就是随i变化如名为:check i end 上面是生成。下面是读: for ( 从i:=0开始到用户填的数) begin if check i .checked then 处理end
type TForm1 = class(TForm) Button1: TButton; //这个按钮是我放在窗体上的按钮,通过单击此按钮动态生成一个新的按钮 procedure Button1Click(Sender: TObject); private { Private declarations } procedure buttonClickEvent(sender:TObject); //手动添加 public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm} procedure TForm1.buttonClickEvent(sender:TObject); //手动添加函数的实现 begin showMessage('asdlfj;lasdkfj;asdlfjasl'); end;procedure TForm1.Button1Click(Sender: TObject); var button:TButton; //这里动态生成一个按钮 begin button:=TButton.Create(form1); button.Caption:='http://www.goomoo.net'; button.Left:=20; button.Width:=300; button.Top:=20; button.OnClick:=buttonClickEvent; button.Parent:=form1; end;
var n :Integer; aa: TButton; begin for n := 1 to 10 do begin aa := TButton.Create(Self); aa.Parent := Form1; aa.Name := 'Test' + IntToStr(n); aa.Top := n * 10; aa.Left := n * 20; end; end;如果是checkbox或radio改一下就可以了
可到我网站看看www.52007.8u8.com
procedure TForm1.Button1Click(Sender: TObject); var tt:array of tlabel; i:integer; begin for i:=1 to 10 do //可以动态生成不定的对象1 to 20 就是20个 begin setlength(tt,i); tt[i-1]:=tlabel.create(form1); tt[i-1].parent:=form1; tt[i-1].left:=10+i*20; tt[i-1].Top :=1; tt[i-1].width:=10; tt[i-1].caption:=inttostr(i); edit4.Text:=tt[5].Caption; //在这里出错了! end; end; 上面的代码为什么错误了呢?
xianxiliu(林桤) : 你的网站,我去了也。整个网叶都是你自己做的么?连同那个07的软件?你太牛了!另外,我照您的提示做了,如下: var n :Integer; aa: TCheckBox; begin for n := 1 to 10 do begin aa := TCheckBox.Create(Self); aa.Parent := Form1; aa.Name := 'Test' + IntToStr(n); aa.Top := n * 30; aa.Left := 40; end; end; 问题是,我怎么才能够知道某个CheckBox被选中了呢?
begin
if sender is tbutton then
ShowMessage(inttostr((sender as tbutton).tag)));
end;
可以这样
with btn[1] do
begin
Tag:=1;
OnClick:=MyProc;
end;....
Form1: TForm1;
btn:array[0..9] of TButton;var
i:Integer;begin
for i := 0 to 9 do
begin
btn[i]:=TButton.Create(Self);
with btn[i] do
begin
Top:=30*i;
Left:=0;
Show;
OnClick:=ButtonClick;
end;
end;
end;procedure TForm.ButtonClick(Sender:TObject)
begin
if (Sender as TButton)=btn[0] then
...
else (Sender as TButton)=btn[1] then
...
...
end;
for ( 从i:=0开始到用户填的数)
begin
new 生成checkbox 每个的区别就是随i变化如名为:check i
end
上面是生成。下面是读:
for ( 从i:=0开始到用户填的数)
begin
if check i .checked then
处理end
TForm1 = class(TForm)
Button1: TButton; //这个按钮是我放在窗体上的按钮,通过单击此按钮动态生成一个新的按钮
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure buttonClickEvent(sender:TObject); //手动添加
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
procedure TForm1.buttonClickEvent(sender:TObject); //手动添加函数的实现
begin
showMessage('asdlfj;lasdkfj;asdlfjasl');
end;procedure TForm1.Button1Click(Sender: TObject);
var
button:TButton; //这里动态生成一个按钮
begin
button:=TButton.Create(form1);
button.Caption:='http://www.goomoo.net';
button.Left:=20;
button.Width:=300;
button.Top:=20;
button.OnClick:=buttonClickEvent;
button.Parent:=form1;
end;
我以前看到好象就是你说的这种,可是,能否麻烦您一下给一个比较具体的例子呢?
比如,你说的New是怎么个用法呢?
n :Integer;
aa: TButton;
begin
for n := 1 to 10 do
begin
aa := TButton.Create(Self);
aa.Parent := Form1;
aa.Name := 'Test' + IntToStr(n);
aa.Top := n * 10;
aa.Left := n * 20;
end;
end;如果是checkbox或radio改一下就可以了
var
tt:array of tlabel;
i:integer;
begin
for i:=1 to 10 do //可以动态生成不定的对象1 to 20 就是20个
begin
setlength(tt,i);
tt[i-1]:=tlabel.create(form1);
tt[i-1].parent:=form1;
tt[i-1].left:=10+i*20;
tt[i-1].Top :=1;
tt[i-1].width:=10;
tt[i-1].caption:=inttostr(i);
edit4.Text:=tt[5].Caption; //在这里出错了!
end;
end;
上面的代码为什么错误了呢?
你的网站,我去了也。整个网叶都是你自己做的么?连同那个07的软件?你太牛了!另外,我照您的提示做了,如下:
var
n :Integer;
aa: TCheckBox;
begin
for n := 1 to 10 do
begin
aa := TCheckBox.Create(Self);
aa.Parent := Form1;
aa.Name := 'Test' + IntToStr(n);
aa.Top := n * 30;
aa.Left := 40;
end;
end;
问题是,我怎么才能够知道某个CheckBox被选中了呢?
对不起我在上面的代码中犯了一个极其愚蠢的错误了。我应该把Edit4.text:=aa[5].caption放在循环的外面的。问题总算是有了眉目了。谢谢楼上的二位了。加分揭贴了!