1unit rptshapes;
2
3
4{$mode objfpc}{$H+}
5{$I demos.inc}
6
7interface
8
9uses
10  Classes,
11  SysUtils,
12  fpreport,
13{$IFDEF USEPOLYGON}
14  reportpolygon,
15{$ENDIF}
16  udapp;
17
18type
19
20  { TShapesDemo }
21
22  TShapesDemo = class(TReportDemoApp)
23  private
24    lReportData: TFPReportUserData;
25    sl: TStringList;
26    procedure   GetReportDataFirst(Sender: TObject);
27    procedure   GetReportDataValue(Sender: TObject; const AValueName: String; var AValue: Variant);
28    procedure   GetReportDataEOF(Sender: TObject; var IsEOF: Boolean);
29  protected
30    procedure   InitialiseData; override;
31    procedure   CreateReportDesign; override;
32  public
33    constructor Create(AOwner : TComponent); override;
34    destructor  Destroy; override;
35    Class function Description : string; override;
36  end;
37
38
39implementation
40
41uses
42  fpTTF;
43
44{ TShapesDemo }
45
46procedure TShapesDemo.GetReportDataFirst(Sender: TObject);
47begin
48  {$IFDEF gdebug}
49  writeln('GetReportDataFirst');
50  {$ENDIF}
51end;
52
53procedure TShapesDemo.GetReportDataValue(Sender: TObject; const AValueName: String; var AValue: Variant);
54begin
55  {$IFDEF gdebug}
56  writeln(Format('GetReportDataValue - %d', [lReportData.RecNo]));
57  {$ENDIF}
58  if AValueName = 'element' then
59  begin
60    AValue := sl[lReportData.RecNo-1];
61  end;
62end;
63
64procedure TShapesDemo.GetReportDataEOF(Sender: TObject; var IsEOF: Boolean);
65begin
66  {$IFDEF gdebug}
67  writeln(Format('GetReportDataEOF - %d', [lReportData.RecNo]));
68  {$ENDIF}
69  if lReportData.RecNo > sl.Count then
70    IsEOF := True
71  else
72    IsEOF := False;
73end;
74
75procedure TShapesDemo.InitialiseData;
76var
77  i: integer;
78begin
79  sl := TStringList.Create;
80  for i := 1 to 10 do
81    sl.Add(Format('Item %d', [i]));
82end;
83
84procedure TShapesDemo.CreateReportDesign;
85var
86  p: TFPReportPage;
87  TitleBand: TFPReportTitleBand;
88  Memo: TFPReportMemo;
89  Shape: TFPReportShape;
90{$IFDEF USEPOLYGON}
91  Poly : TReportPolygon;
92{$ENDIF}
93begin
94  Inherited;
95  rpt.Author := 'Graeme Geldenhuys';
96  rpt.Title := 'FPReport Demo 6 - Shapes';
97
98  p := TFPReportPage.Create(rpt);
99  p.Orientation := poPortrait;
100  p.PageSize.PaperName := 'A4';
101  { page margins }
102  p.Margins.Left := 30;
103  p.Margins.Top := 20;
104  p.Margins.Right := 30;
105  p.Margins.Bottom := 20;
106  p.Data := lReportData;
107  p.Font.Name := 'LiberationSans';
108
109  TitleBand := TFPReportTitleBand.Create(p);
110  TitleBand.Layout.Height := 200;
111  {$ifdef ColorBands}
112  TitleBand.Frame.Shape := fsRectangle;
113  TitleBand.Frame.BackgroundColor := clReportTitleSummary;
114  {$endif}
115
116  Memo := TFPReportMemo.Create(TitleBand);
117  Memo.Layout.Left := 40;
118  Memo.Layout.Top := 0;
119  Memo.Layout.Width := 100;
120  Memo.Layout.Height := 20;
121  Memo.Text := 'Demo 6 - Shapes';
122  Memo.UseParentFont := False;
123  Memo.Font.Size := 24;
124
125  Shape := TFPReportShape.Create(TitleBand);
126  Shape.Layout.Left := 0;
127  Shape.Layout.Top := 40;
128  Shape.Layout.Width := 40;
129  Shape.Layout.Height := 25;
130  Shape.ShapeType := stEllipse;
131  Shape.Frame.Shape := fsRectangle;
132  Shape.Frame.BackgroundColor := TFPReportColor($E0E0E0);
133
134  Shape := TFPReportShape.Create(TitleBand);
135  Shape.Layout.Left := 55;
136  Shape.Layout.Top := 40;
137  Shape.Layout.Width := 40;
138  Shape.Layout.Height := 25;
139  Shape.ShapeType := stCircle;
140  Shape.Color:=clRed;
141  Shape.Frame.Shape := fsRectangle;
142  Shape.Frame.BackgroundColor := TFPReportColor($E0E0E0);
143
144  Shape := TFPReportShape.Create(TitleBand);
145  Shape.Layout.Left := 110;
146  Shape.Layout.Top := 40;
147  Shape.Layout.Width := 40;
148  Shape.Layout.Height := 25;
149  Shape.ShapeType := stLine;
150//  Shape.Orientation := orNorth;
151//  Shape.Orientation := orSouth;
152//  Shape.Orientation := orEast;
153//  Shape.Orientation := orWest;
154//  Shape.Orientation := orNorthWest;
155//  Shape.Orientation := orSouthEast;
156//  Shape.Orientation := orNorthEast;
157  Shape.Orientation := orSouthWest;
158  Shape.Frame.Shape := fsRectangle;
159  Shape.Frame.BackgroundColor := TFPReportColor($E0E0E0);
160
161  Shape := TFPReportShape.Create(TitleBand);
162  Shape.Layout.Left := 0;
163  Shape.Layout.Top := 75;
164  Shape.Layout.Width := 40;
165  Shape.Layout.Height := 25;
166  Shape.ShapeType := stSquare;
167  Shape.Frame.Shape := fsRectangle;
168  Shape.Frame.BackgroundColor := TFPReportColor($E0E0E0);
169
170  Shape := TFPReportShape.Create(TitleBand);
171  Shape.Layout.Left := 55;
172  Shape.Layout.Top := 75;
173  Shape.Layout.Width := 40;
174  Shape.Layout.Height := 25;
175  Shape.ShapeType := stTriangle;
176//  Shape.Orientation := orNorth;
177//  Shape.Orientation := orSouth;
178//  Shape.Orientation := orEast;
179//  Shape.Orientation := orWest;
180  Shape.Orientation := orNorthEast;
181//  Shape.Orientation := orSouthWest;
182//  Shape.Orientation := orSouthEast;
183//  Shape.Orientation := orNorthWest;
184  Shape.Frame.Shape := fsRectangle;
185  Shape.Frame.BackgroundColor := TFPReportColor($E0E0E0);
186
187  Shape := TFPReportShape.Create(TitleBand);
188  Shape.Layout.Left := 110;
189  Shape.Layout.Top := 75;
190  Shape.Layout.Width := 40;
191  Shape.Layout.Height := 25;
192  Shape.ShapeType := stRoundedRect;
193  Shape.Color:=clBlue;
194//  Shape.CornerRadius := 2;
195  Shape.Frame.Shape := fsRectangle;
196  Shape.Frame.BackgroundColor := TFPReportColor($E0E0E0);
197
198{$IFDEF USEPOLYGON}
199  Poly := TReportPolygon.Create(TitleBand);
200  Poly.Layout.Left := 0;
201  Poly.Layout.Top := 110;
202  Poly.Layout.Width := 40;
203  Poly.Layout.Height := 25;
204  Poly.Corners:=5;
205  Poly.Color:=clRed;
206  Poly.LineWidth:=2;
207  Poly.Frame.Shape := fsRectangle;
208  Poly.Frame.BackgroundColor := TFPReportColor($E0E0E0);
209{$ENDIF}
210
211end;
212
213constructor TShapesDemo.Create(AOwner : TComponent);
214begin
215  Inherited;
216  lReportData := TFPReportUserData.Create(self);
217  lReportData.OnGetValue := @GetReportDataValue;
218  lReportData.OnGetEOF := @GetReportDataEOF;
219  lReportData.OnFirst := @GetReportDataFirst;
220end;
221
222destructor TShapesDemo.Destroy;
223begin
224  FreeAndNil(lReportData);
225  FreeAndNil(sl);
226  inherited Destroy;
227end;
228
229class function TShapesDemo.Description: string;
230begin
231  Result:='Demo showing support for shapes';
232end;
233
234
235
236end.
237
238