rptframes.pp 8.1 KB

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