Advertisement
WISNUWIDIARTA

Mystery of TObjectList

Sep 30th, 2012
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.82 KB | None | 0 0
  1. procedure TformMain.btnTestClick(Sender: TObject);
  2. var
  3.   btn: TButton;
  4.   btnCollection: TObjectList<TButton>;
  5.   i: integer;
  6. begin
  7.   btnCollection := TObjectList<TButton>.Create(True);
  8.  
  9.   for i := 0 to 10 do
  10.   begin
  11.     btn := TButton.Create(Nil);
  12.     btn.Parent := Self;
  13.     btn.Left := i * 10;
  14.     btn.Width := 100;
  15.     btn.Top := 100;
  16.     btn.Caption := VarToStr(i);
  17.     btnCollection.Add(btn);
  18.   end;
  19.  
  20.   btnCollection.Free;
  21.  
  22.   btnCollection := TObjectList<TButton>.Create(False);
  23.  
  24.   for i := 0 to 10 do
  25.   begin
  26.     btn := TButton.Create(Nil);
  27.     btn.Parent := Self;
  28.     btn.Left := i * 10;
  29.     btn.Width := 100;
  30.     btn.Top := 100;
  31.     btn.Caption := VarToStr(i);
  32.     btnCollection.Add(btn);
  33.   end;
  34.  
  35.   for i := 0 to 10 do
  36.   begin
  37.     btnCollection.Items[i].Free;
  38.   end;
  39.  
  40.   btnCollection.Free;
  41. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement