Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls;
- type
- TForm1 = class(TForm)
- Button1: TButton;
- Button2: TButton;
- Button3: TButton;
- const Test:Array[0..2] of TButton = (Button1,Button2,Button3);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- end.
- var TestA:TObjectList<TButton>;
- var index:TComponent;
- begin
- TestA := TObjectList<TButton>.Create(false);
- for index in Form7 do
- if pos(index.name, 'Button') = 1 then
- TestA.add(TButton(index));
- TestA[0].Caption := 'Test'; //Exception out of range.
- var
- index: TComponent;
- list: TObjectList;
- begin
- list := TObjectList.Create(false); //DO NOT take ownership
- for index in frmMyForm do
- if pos('Button', index.name) = 1 then
- list.add(index);
- //do more stuff once the list is built
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- Test[0] := Button1;
- Test[1] := Button2;
- Test[2] := Button3;
- end;
- procedure TForm1.AddImageControlsToList(AParent: TWinControl; AList: TObjectList; Recursive: boolean);
- var
- Index: integer;
- AChild: TControl;
- begin
- for Index := 0 to AParent.ControlCount - 1 do
- begin
- AChild := AParent.Controls[Index];
- if AChild is TImage then // Or whatever test you want to use
- AList.Add(AChild)
- else if Recursive and (AChild is TWinControl) then
- AddImageControlsToList(TWinControl(AChild), AList, True);
- end;
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- // Call like this or similar to get your list of images
- // (assumes MyImageList is declared in Form)
- MyImageList := TObjectList.Create(False);
- AddImageControlsToList(Self, MyImageList, True);
- end;
- procedure TForm1.FormDestroy(Sender: TObject);
- begin
- // Destroy the list
- FreeAndNil(MyImageList);
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- for b := 1 to 110 do
- Test[b] := FindComponent('Button' + IntToStr(b)) as TButton;
- end;
- new(pbutton[k]);
- pbutton[k]^:= tbutton(FindComponent('Button'+IntToStr(k)));
- begin
- { found it so do something}
- b:=true;
- end;
- k:=k+1;
Add Comment
Please, Sign In to add comment