导航:
论坛 -> DELPHI技术
斑竹:liumazi,sephil
作者:
bcm (bcm)
★☆☆☆☆
-
普通会员
2004/2/13 15:06:42
标题:
怎么样把控件做为数组来使用,能给一个例子吗?
浏览:1492
加入我的收藏
楼主:
谁能告诉我怎么样把控件做为数组来使用,能否给一个例子? 谢谢!!
----------------------------------------------
bcm
作者:
2004/2/13 15:29:18
1楼:
控件作为数组? 呃。。。。不明白
----------------------------------------------
夫君子之行,静以修身,俭以养德.非澹泊无以明志, 非宁静无以致远.夫学须静也,才须学也,非学无以广才, 非志无以成学,淫漫则不能励精,险躁则不能治性,年与时驰, 意与日去,遂成枯落,多不接世,悲守穷庐,将复何及!
作者:
2004/2/13 15:36:38
1楼:
//Delphi里使用控件数组.只能动态创建. unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; const iMax = 5; type TForm1 = class(TForm) btn1: TButton; procedure btn1Click(Sender: TObject); private { Private declarations } procedure btnClick(Sender: TObject); public { Public declarations } end; var Form1: TForm1; MyButton: array[0..iMax] of TButton; implementation {$R *.dfm} procedure TForm1.btn1Click(Sender: TObject); var i: Integer; begin for i := 0 to iMax - 1 do begin MyButton[i] := TButton.Create(Application); if i = 0 then begin MyButton[i].Width := 50; MyButton[i].Height := 30; MyButton[i].Top := 1; MyButton[i].Left := 1; MyButton[i].Parent := Self; MyButton[i].Visible := True; MyButton[i].Caption := 'Button' + IntToStr(i); MyButton[i].Tag := i; MyButton[i].OnClick := btnClick; end else begin MyButton[i].Width := 50; MyButton[i].Height := 30; MyButton[i].Top := MyButton[i-1].Top; MyButton[i].Left := MyButton[i-1].Left + MyButton[i-1].Width + 2; MyButton[i].Parent := Self; MyButton[i].Visible := True; MyButton[i].Caption := 'Button' + IntToStr(i); MyButton[i].Tag := i; MyButton[i].OnClick := btnClick; end; end; end; procedure TForm1.btnClick(Sender: TObject); var i: Integer; str: String; begin i := (Sender as TButton).Tag; str := '你单击的是Button' + IntToStr(i); Application.MessageBox(PChar(str), '说明', MB_OK); end; end.
----------------------------------------------
-
作者:
sephil (NAILY Soft)
★☆☆☆☆
-
盒子中级会员
2004/2/13 15:47:41
2楼:
简单的应用你可以用FindComponent模拟一个 var I: Integer; E: TEdit; begin for I := 1 to 10 do begin E := FindComponent('Edit' + IntToStr(I)) as TEdit; if Assigned(E) then E.Text := '; end; end; 上面的代码将名为Edit1到Edit10的10个TEdit的内容清空 楼上的用法也可以,但是并非一定要动态创建才行
----------------------------------------------
Copyright 2008 ? NAILY Soft
Click here to redirect to my home Click here to redirect to my blog
作者:
2004/2/13 15:48:46
2楼:
学习!
----------------------------------------------
=^@^=
作者:
2004/2/13 16:10:16
3楼:
晕了. 你那样用.并非数组啊
----------------------------------------------
-
作者:
sephil (NAILY Soft)
★☆☆☆☆
-
盒子中级会员
2004/2/13 18:08:02
4楼:
var EditArray: array[0..9] of TEdit; .................. procedure TForm.Create(Sender: TObject); var I: Integer; E: TEdit; begin for I := 1 to 10 do begin E := FindComponent('Edit' + IntToStr(I)) as TEdit; if Assigned(E) then EditArray[I - 1] := E; end; end;
----------------------------------------------
Copyright 2008 ? NAILY Soft
Click here to redirect to my home Click here to redirect to my blog
作者:
bios (阿贡)
★☆☆☆☆
-
盒子中级会员
2004/2/13 20:02:50
5楼:
同意 sephil 老大 大家不要这么死脑筋嘛!
----------------------------------------------
作者:
2004/2/15 11:40:31
6楼:
照三楼的代码试过了,提示没有TBUTTON类型,怎么回事
----------------------------------------------
-
作者:
2004/2/15 13:05:32
7楼:
有没有包含StdCtrls单元
----------------------------------------------
-