1unit rptframes;
2
3{$mode objfpc}{$H+}
4{$I demos.inc}
5
6interface
7
8uses
9  Classes,
10  SysUtils,
11  fpreport,
12  udapp;
13
14type
15
16  { TFramesDemo }
17
18  TFramesDemo = class(TReportDemoApp)
19  private
20    lReportData: TFPReportUserData;
21    sl: TStringList;
22    procedure   GetReportDataFirst(Sender: TObject);
23    procedure   GetReportDataValue(Sender: TObject; const AValueName: String; var AValue: Variant);
24    procedure   GetReportDataEOF(Sender: TObject; var IsEOF: Boolean);
25    procedure   GetReportFieldNames(Sender: TObject; List: TStrings);
26
27  protected
28    procedure   InitialiseData; override;
29    procedure   CreateReportDesign; override;
30  public
31    constructor Create(AOwner : TComponent) ; override;
32    destructor  Destroy; override;
33    Class function Description : string; override;
34  end;
35
36
37implementation
38
39uses
40  FPCanvas,
41  fpTTF;
42
43{ TFramesDemo }
44
45procedure TFramesDemo.GetReportDataFirst(Sender: TObject);
46begin
47  {$IFDEF gdebug}
48  writeln('GetReportDataFirst');
49  {$ENDIF}
50end;
51
52procedure TFramesDemo.GetReportDataValue(Sender: TObject; const AValueName: String; var AValue: Variant);
53begin
54  {$IFDEF gdebug}
55  writeln(Format('GetReportDataValue - %d', [lReportData.RecNo]));
56  {$ENDIF}
57  if AValueName = 'country' then
58  begin
59    AValue := sl.Names[lReportData.RecNo-1];
60  end
61  else if AValueName = 'population' then
62  begin
63    AValue := sl.Values[sl.Names[lReportData.RecNo-1]];
64  end;
65end;
66
67procedure TFramesDemo.GetReportDataEOF(Sender: TObject; var IsEOF: Boolean);
68begin
69  {$IFDEF gdebug}
70  writeln(Format('GetReportDataEOF - %d', [lReportData.RecNo]));
71  {$ENDIF}
72  if lReportData.RecNo > sl.Count then
73    IsEOF := True
74  else
75    IsEOF := False;
76end;
77
78procedure TFramesDemo.GetReportFieldNames(Sender: TObject; List: TStrings);
79begin
80  {$IFDEF gdebug}
81  writeln('********** GetReportFieldNames');
82  {$ENDIF}
83  List.Add('country');
84  List.Add('population');
85end;
86
87procedure TFramesDemo.InitialiseData;
88begin
89  sl := TStringList.Create;
90  {$I countries.inc}
91  sl.Sort;
92end;
93
94procedure TFramesDemo.CreateReportDesign;
95var
96  p: TFPReportPage;
97  TitleBand: TFPReportTitleBand;
98  DataBand: TFPReportDataBand;
99  GroupHeader: TFPReportGroupHeaderBand;
100  Memo: TFPReportMemo;
101  PageFooter: TFPReportPageFooterBand;
102  ReportSummary: TFPReportSummaryBand;
103  PageHeader: TFPReportPageHeaderBand;
104begin
105  Inherited;
106
107  rpt.Author := 'Graeme Geldenhuys';
108  rpt.Title := 'FPReport Demo 4 - Frames and Fonts';
109
110  p :=  TFPReportPage.Create(rpt);
111  p.Orientation := poPortrait;
112  p.PageSize.PaperName := 'A4';
113  { page margins }
114  p.Margins.Left := 30;
115  p.Margins.Top := 20;
116  p.Margins.Right := 30;
117  p.Margins.Bottom := 20;
118  p.Data := lReportData;
119  p.Font.Name := 'LiberationSans';
120
121  TitleBand := TFPReportTitleBand.Create(p);
122  TitleBand.Layout.Height := 40;
123  {$ifdef ColorBands}
124  TitleBand.Frame.Shape := fsRectangle;
125  TitleBand.Frame.BackgroundColor := clReportTitleSummary;
126  {$endif}
127
128  Memo := TFPReportMemo.Create(TitleBand);
129  Memo.Layout.Left := 5;
130  Memo.Layout.Top := 0;
131  Memo.Layout.Width := 140;
132  Memo.Layout.Height := 15;
133  Memo.Text := 'Country and Population as of 2014';
134  Memo.TextAlignment.Vertical := tlCenter;
135  Memo.TextAlignment.Horizontal := taCentered;
136  Memo.UseParentFont := False;
137  Memo.Font.Color := clNavy;
138  Memo.Font.Name := 'LiberationSerif';
139  Memo.Font.Size := 24;
140
141  PageHeader := TFPReportPageHeaderBand.Create(p);
142  PageHeader.Layout.Height := 30;
143  {$ifdef ColorBands}
144  PageHeader.Frame.Shape := fsRectangle;
145  PageHeader.Frame.BackgroundColor := clPageHeaderFooter;
146  {$endif}
147
148  Memo := TFPReportMemo.Create(PageHeader);
149  Memo.Layout.Left := 55;
150  Memo.Layout.Top := 15;
151  Memo.Layout.Width := 50;
152  Memo.Layout.Height := 10;
153  Memo.Text := 'PageHeader band';
154
155  GroupHeader := TFPReportGroupHeaderBand.Create(p);
156  GroupHeader.Layout.Height := 15;
157  GroupHeader.GroupCondition := 'copy(''[country]'',1,1)';
158  GroupHeader.Frame.Color := clNavy;
159  GroupHeader.Frame.Pen := psDashDot;
160  {$ifdef ColorBands}
161  GroupHeader.Frame.Shape := fsRectangle;
162  GroupHeader.Frame.BackgroundColor := clGroupHeaderFooter;
163  {$endif}
164
165  Memo := TFPReportMemo.Create(GroupHeader);
166  Memo.Layout.Left := 0;
167  Memo.Layout.Top := 5;
168  Memo.Layout.Width := 10;
169  Memo.Layout.Height := 8;
170  Memo.Text := '[copy(country,1,1)]';
171  Memo.UseParentFont := False;
172  Memo.Font.Size := 16;
173  Memo.Font.Color := TFPReportColor($C00000);
174  Memo.Frame.Shape := fsRectangle;
175  Memo.Frame.Color := TFPReportColor($008080);
176  Memo.Frame.Pen := psDot;
177
178  DataBand := TFPReportDataBand.Create(p);
179  DataBand.Layout.Height := 8;
180  {$ifdef ColorBands}
181  DataBand.Frame.Shape := fsRectangle;
182  DataBand.Frame.BackgroundColor := clDataBand;
183  {$endif}
184
185  Memo := TFPReportMemo.Create(DataBand);
186  Memo.Layout.Left := 15;
187  Memo.Layout.Top := 0;
188  Memo.Layout.Width := 50;
189  Memo.Layout.Height := 5;
190  Memo.Text := '[country]';
191  Memo.TextAlignment.Vertical := tlCenter;
192
193  Memo := TFPReportMemo.Create(DataBand);
194  Memo.Layout.Left := 70;
195  Memo.Layout.Top := 0;
196  Memo.Layout.Width := 30;
197  Memo.Layout.Height := 5;
198  Memo.Text := '[formatfloat(''#,##0'', StrToFloat(population))]';
199  Memo.TextAlignment.Vertical := tlCenter;
200  Memo.TextAlignment.Horizontal := taRightJustified;
201
202  PageFooter := TFPReportPageFooterBand.Create(p);
203  PageFooter.Layout.Height := 20;
204  {$ifdef ColorBands}
205  PageFooter.Frame.Shape := fsRectangle;
206  PageFooter.Frame.BackgroundColor := clPageHeaderFooter;
207  {$endif}
208
209  Memo := TFPReportMemo.Create(PageFooter);
210  Memo.Layout.Left := 130;
211  Memo.Layout.Top := 13;
212  Memo.Layout.Width := 20;
213  Memo.Layout.Height := 5;
214  Memo.Text := 'Page [PageNo]';
215  Memo.TextAlignment.Vertical := tlCenter;
216  Memo.TextAlignment.Horizontal := taRightJustified;
217
218  { ReportSummary could have been designed before PageFooter. The layouting
219    will sort out the order anyway. }
220  ReportSummary := TFPReportSummaryBand.Create(p);
221  ReportSummary.Layout.Height := 60;
222  ReportSummary.StartNewPage := True;
223  {$ifdef ColorBands}
224  ReportSummary.Frame.Shape := fsRectangle;
225  ReportSummary.Frame.BackgroundColor := clReportTitleSummary;
226  {$endif}
227  ReportSummary.UseParentFont := False;
228  ReportSummary.Font.Size := 8;
229
230  Memo := TFPReportMemo.Create(ReportSummary);
231  Memo.Layout.Left := 3;
232  Memo.Layout.Top := 3;
233  Memo.Layout.Width := 100;
234  Memo.Layout.Height := 5;
235  Memo.Text := 'This block is the ReportSummary band - forced on a new page.';
236
237  Memo := TFPReportMemo.Create(ReportSummary);
238  Memo.Layout.Left := 20;
239  Memo.Layout.Top := 10;
240  Memo.Layout.Width := 30;
241  Memo.Layout.Height := 15;
242  Memo.Text := 'Lines: Left & Bottom';
243  Memo.TextAlignment.Vertical := tlCenter;
244  Memo.TextAlignment.Horizontal := taCentered;
245  Memo.Frame.Color := clNavy;
246  Memo.Frame.Lines := [flLeft, flBottom];
247
248  Memo := TFPReportMemo.Create(ReportSummary);
249  Memo.Layout.Left := 90;
250  Memo.Layout.Top := 10;
251  Memo.Layout.Width := 30;
252  Memo.Layout.Height := 15;
253  Memo.Text := 'Lines: Top & Right';
254  Memo.TextAlignment.Vertical := tlCenter;
255  Memo.TextAlignment.Horizontal := taCentered;
256  Memo.Frame.Color := clNavy;
257  Memo.Frame.Lines := [flTop, flRight];
258
259  Memo := TFPReportMemo.Create(ReportSummary);
260  Memo.Layout.Left := 20;
261  Memo.Layout.Top := 40;
262  Memo.Layout.Width := 30;
263  Memo.Layout.Height := 15;
264  Memo.Text := 'Lines: Top & Bottom';
265  Memo.TextAlignment.Vertical := tlCenter;
266  Memo.TextAlignment.Horizontal := taCentered;
267  Memo.Frame.Color := clNavy;
268  Memo.Frame.Lines := [flTop, flBottom];
269
270  Memo := TFPReportMemo.Create(ReportSummary);
271  Memo.Layout.Left := 90;
272  Memo.Layout.Top := 40;
273  Memo.Layout.Width := 30;
274  Memo.Layout.Height := 15;
275  Memo.Text := 'Lines: Left & Right';
276  Memo.TextAlignment.Vertical := tlCenter;
277  Memo.TextAlignment.Horizontal := taCentered;
278  Memo.Frame.Color := clNavy;
279  Memo.Frame.Lines := [flLeft, flRight];
280end;
281
282constructor TFramesDemo.Create(AOwner: TComponent);
283begin
284  inherited;
285  lReportData := TFPReportUserData.Create(nil);
286  lReportData.OnGetValue := @GetReportDataValue;
287  lReportData.OnGetEOF := @GetReportDataEOF;
288  lReportData.OnFirst := @GetReportDataFirst;
289  lReportData.OnGetNames := @GetReportFieldNames;
290end;
291
292destructor TFramesDemo.Destroy;
293begin
294  FreeAndNil(lReportData);
295  FreeAndNil(sl);
296  inherited Destroy;
297end;
298
299class function TFramesDemo.Description: string;
300begin
301  Result:='Demo showing frames around elements';
302end;
303
304
305end.
306
307