|
|
#2
anthony6342008-02-20 21:11
你说的是不是delphi的数组属性啊?
type TArrButton = array of TButton; TTestProperty = class(TObject) private fButton: TArrButton; function getaButton(i: Integer): TButton; public constructor Create(alength: Integer); destructor destroy(); override; property MyButton[index: Integer]: TButton read getaButton; end; TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; Edit1: TEdit; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } fTestProperty: TTestProperty; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} { TTestProperty } constructor TTestProperty.Create(alength: Integer); var I: Integer; begin SetLength(fButton, 10); for i := Low(fButton) to High(fButton) do begin fButton[i] := TButton.Create(nil); fButton[i].SetBounds(50*i, 50*i, 10*i, 10*i); fButton[i].Parent := Form1; fButton[i].Name := TButton.ClassName; fButton[i].Caption := IntToStr(i) + ' 什么啊 '; end; end; destructor TTestProperty.destroy; var I: Integer; begin for i := Low(fButton) to High(fButton) do begin FreeAndNil(fButton[i]); end; SetLength(fButton, 0); inherited destroy(); end; function TTestProperty.getaButton(i: Integer): TButton; begin if (i >= Low(fButton)) and (i <= High(fButton)) then begin Result := fButton[i]; end else begin Result := nil; end; end; procedure TForm1.Button1Click(Sender: TObject); var tempStr: string; index: Integer; begin index := StrToIntDef(Edit1.Text, 0); tempStr := fTestProperty.MyButton[index].Caption; TButton(Sender).Caption := tempStr; end; procedure TForm1.FormCreate(Sender: TObject); begin fTestProperty := TTestProperty.Create(10); end; procedure TForm1.FormDestroy(Sender: TObject); begin fTestProperty.Free(); end; end. |
在vb6中,可以设计控件数组(可视化的控件,如button),在编程实际中很有用,请问如何在delphi2005中实现呢?
如:ommand1[i].text=“”(vb6)