PageRenderTime 21ms CodeModel.GetById 13ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

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