Guest User

Untitled

a guest
May 20th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7. Dialogs, StdCtrls;
  8.  
  9. type
  10. TForm1 = class(TForm)
  11. Button1: TButton;
  12. Button2: TButton;
  13. Button3: TButton;
  14. const Test:Array[0..2] of TButton = (Button1,Button2,Button3);
  15. private
  16. { Private declarations }
  17. public
  18. { Public declarations }
  19. end;
  20.  
  21. var
  22. Form1: TForm1;
  23.  
  24. implementation
  25.  
  26. end.
  27.  
  28. var TestA:TObjectList<TButton>;
  29.  
  30. var index:TComponent;
  31. begin
  32. TestA := TObjectList<TButton>.Create(false);
  33. for index in Form7 do
  34. if pos(index.name, 'Button') = 1 then
  35. TestA.add(TButton(index));
  36.  
  37. TestA[0].Caption := 'Test'; //Exception out of range.
  38.  
  39. var
  40. index: TComponent;
  41. list: TObjectList;
  42. begin
  43. list := TObjectList.Create(false); //DO NOT take ownership
  44. for index in frmMyForm do
  45. if pos('Button', index.name) = 1 then
  46. list.add(index);
  47. //do more stuff once the list is built
  48. end;
  49.  
  50. procedure TForm1.FormCreate(Sender: TObject);
  51. begin
  52. Test[0] := Button1;
  53. Test[1] := Button2;
  54. Test[2] := Button3;
  55. end;
  56.  
  57. procedure TForm1.AddImageControlsToList(AParent: TWinControl; AList: TObjectList; Recursive: boolean);
  58. var
  59. Index: integer;
  60. AChild: TControl;
  61. begin
  62. for Index := 0 to AParent.ControlCount - 1 do
  63. begin
  64. AChild := AParent.Controls[Index];
  65. if AChild is TImage then // Or whatever test you want to use
  66. AList.Add(AChild)
  67. else if Recursive and (AChild is TWinControl) then
  68. AddImageControlsToList(TWinControl(AChild), AList, True);
  69. end;
  70. end;
  71.  
  72. procedure TForm1.FormCreate(Sender: TObject);
  73. begin
  74. // Call like this or similar to get your list of images
  75. // (assumes MyImageList is declared in Form)
  76. MyImageList := TObjectList.Create(False);
  77. AddImageControlsToList(Self, MyImageList, True);
  78. end;
  79.  
  80. procedure TForm1.FormDestroy(Sender: TObject);
  81. begin
  82. // Destroy the list
  83. FreeAndNil(MyImageList);
  84. end;
  85.  
  86. procedure TForm1.FormCreate(Sender: TObject);
  87. begin
  88. for b := 1 to 110 do
  89. Test[b] := FindComponent('Button' + IntToStr(b)) as TButton;
  90. end;
  91.  
  92. new(pbutton[k]);
  93.  
  94. pbutton[k]^:= tbutton(FindComponent('Button'+IntToStr(k)));
  95.  
  96. begin
  97.  
  98. { found it so do something}
  99.  
  100. b:=true;
  101.  
  102. end;
  103.  
  104. k:=k+1;
Add Comment
Please, Sign In to add comment