/components/rtticontrols/examples/examplegrid1.pas

http://github.com/graemeg/lazarus · Pascal · 79 lines · 49 code · 19 blank · 11 comment · 0 complexity · 01fe712a95ec807564edfce462b2a437 MD5 · raw file

  1. unit ExampleGrid1;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, RTTIGrids,
  6. RTTICtrls;
  7. type
  8. { TMyCollectionItem }
  9. TMyCollectionItem = class(TCollectionItem)
  10. private
  11. FInt: integer;
  12. FStr: string;
  13. FColor: TColor;
  14. published
  15. property Color: TColor read FColor write FColor;
  16. property Str: string read FStr write FStr;
  17. property Int: integer read FInt write FInt;
  18. end;
  19. { TForm1 }
  20. TForm1 = class(TForm)
  21. TICheckBox1: TTICheckBox;
  22. TIGrid1: TTIGrid;
  23. procedure Form1Create(Sender: TObject);
  24. procedure Form1Destroy(Sender: TObject);
  25. private
  26. { private declarations }
  27. public
  28. { public declarations }
  29. MyCollection: TCollection;
  30. end;
  31. var
  32. Form1: TForm1;
  33. implementation
  34. {$R examplegrid1.lfm}
  35. { TForm1 }
  36. procedure TForm1.Form1Create(Sender: TObject);
  37. var
  38. NewItem: TMyCollectionItem;
  39. begin
  40. // create a collection with 2 items
  41. MyCollection:=TCollection.Create(TMyCollectionItem);
  42. NewItem:=TMyCollectionItem(MyCollection.Add);
  43. NewItem.Color:=clRed;
  44. NewItem.Str:='Some';
  45. NewItem.Int:=123;
  46. NewItem:=TMyCollectionItem(MyCollection.Add);
  47. NewItem.Color:=clBlue;
  48. NewItem.Str:='Text';
  49. NewItem.Int:=789;
  50. // show the collection
  51. TIGrid1.ListObject:=MyCollection;
  52. end;
  53. procedure TForm1.Form1Destroy(Sender: TObject);
  54. begin
  55. // disconnect collection from grid
  56. TIGrid1.ListObject:=nil;
  57. // free collection
  58. MyCollection.Free;
  59. end;
  60. end.