rptimages.pp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. unit rptimages;
  2. {$mode objfpc}{$H+}
  3. {$I demos.inc}
  4. interface
  5. uses
  6. SysUtils,
  7. Classes,
  8. fpreport,
  9. udapp;
  10. type
  11. { TImagesDemo }
  12. TImagesDemo = class(TReportDemoApp)
  13. private
  14. lReportData: TFPReportUserData;
  15. sl: TStringList;
  16. procedure GetReportDataValue(Sender: TObject; const AValueName: String; var AValue: Variant);
  17. procedure GetReportDataEOF(Sender: TObject; var IsEOF: Boolean);
  18. protected
  19. procedure InitialiseData; override;
  20. procedure CreateReportDesign; override;
  21. public
  22. constructor Create(AOWner : TComponent); override;
  23. destructor Destroy; override;
  24. Class function Description : string; override;
  25. procedure GetReportDataNames(Sender: TObject; List: TStrings);
  26. end;
  27. implementation
  28. uses
  29. fpTTF,
  30. FPCanvas;
  31. { TImagesDemo }
  32. procedure TImagesDemo.GetReportDataValue(Sender: TObject; const AValueName: String; var AValue: Variant);
  33. begin
  34. if AValueName = 'country' then
  35. begin
  36. AValue := sl.Names[lReportData.RecNo-1];
  37. end
  38. else if AValueName = 'population' then
  39. begin
  40. AValue := sl.Values[sl.Names[lReportData.RecNo-1]];
  41. end;
  42. end;
  43. procedure TImagesDemo.GetReportDataEOF(Sender: TObject; var IsEOF: Boolean);
  44. begin
  45. if lReportData.RecNo > sl.Count then
  46. IsEOF := True
  47. else
  48. IsEOF := False;
  49. end;
  50. procedure TImagesDemo.InitialiseData;
  51. begin
  52. sl := TStringList.Create;
  53. {$I countries.inc}
  54. sl.Sort;
  55. end;
  56. procedure TImagesDemo.CreateReportDesign;
  57. var
  58. p: TFPReportPage;
  59. TitleBand: TFPReportTitleBand;
  60. DataBand: TFPReportDataBand;
  61. Memo: TFPReportMemo;
  62. PageFooter: TFPReportPageFooterBand;
  63. PageHeader: TFPReportPageHeaderBand;
  64. Image: TFPReportImage;
  65. Checkbox: TFPReportCheckbox;
  66. begin
  67. Inherited;
  68. rpt.Author := 'Graeme Geldenhuys';
  69. rpt.Title := 'FPReport Demo 7 - Images and Checkboxes';
  70. p := TFPReportPage.Create(rpt);
  71. p.Orientation := poPortrait;
  72. p.PageSize.PaperName := 'A4';
  73. { page margins }
  74. p.Margins.Left := 30;
  75. p.Margins.Top := 20;
  76. p.Margins.Right := 30;
  77. p.Margins.Bottom := 20;
  78. p.Data := lReportData;
  79. p.Font.Name := 'LiberationSans';
  80. TitleBand := TFPReportTitleBand.Create(p);
  81. TitleBand.Layout.Height := 40;
  82. {$ifdef ColorBands}
  83. TitleBand.Frame.Shape := fsRectangle;
  84. TitleBand.Frame.BackgroundColor := clReportTitleSummary;
  85. {$endif}
  86. Memo := TFPReportMemo.Create(TitleBand);
  87. Memo.Layout.Left := 5;
  88. Memo.Layout.Top := 0;
  89. Memo.Layout.Width := 140;
  90. Memo.Layout.Height := 15;
  91. Memo.Text := 'Country and Population as of 2014';
  92. Memo.TextAlignment.Vertical := tlCenter;
  93. Memo.TextAlignment.Horizontal := taCentered;
  94. Memo.UseParentFont := False;
  95. Memo.Font.Color := TFPReportColor($000080);
  96. Memo.Font.Name := 'LiberationSerif';
  97. Memo.Font.Size := 24;
  98. PageHeader := TFPReportPageHeaderBand.Create(p);
  99. PageHeader.Layout.Height := 8;
  100. PageHeader.Frame.BackgroundColor := TFPReportColor($000080);
  101. PageHeader.Frame.Shape := fsRectangle;
  102. PageHeader.VisibleOnPage := vpNotOnFirst;
  103. {$ifdef ColorBands}
  104. PageHeader.Frame.Shape := fsRectangle;
  105. PageHeader.Frame.BackgroundColor := clPageHeaderFooter;
  106. {$endif}
  107. PageHeader.UseParentFont := False;
  108. PageHeader.Font.Color := clWhite;
  109. Memo := TFPReportMemo.Create(PageHeader);
  110. Memo.Layout.Left := 15;
  111. Memo.Layout.Top := 1.5;
  112. Memo.Layout.Width := 30;
  113. Memo.Layout.Height := 5;
  114. Memo.Text := 'Country';
  115. Memo.TextAlignment.Vertical := tlCenter;
  116. {$ifdef ColorBands}
  117. // just so the text is visible in this situation
  118. Memo.Frame.Shape := fsRectangle;
  119. Memo.Frame.BackgroundColor := clNavy;
  120. {$endif}
  121. Memo := TFPReportMemo.Create(PageHeader);
  122. Memo.Layout.Left := 70;
  123. Memo.Layout.Top := 1.5;
  124. Memo.Layout.Width := 30;
  125. Memo.Layout.Height := 5;
  126. Memo.Text := 'Population';
  127. Memo.TextAlignment.Vertical := tlCenter;
  128. Memo.TextAlignment.Horizontal := taRightJustified;
  129. {$ifdef ColorBands}
  130. // just so the text is visible in this situation
  131. Memo.Frame.Shape := fsRectangle;
  132. Memo.Frame.BackgroundColor := clNavy;
  133. {$endif}
  134. Memo := TFPReportMemo.Create(PageHeader);
  135. Memo.Layout.Left := 115;
  136. Memo.Layout.Top := 1.5;
  137. Memo.Layout.Width := 30;
  138. Memo.Layout.Height := 5;
  139. Memo.Text := '> 30 million';
  140. Memo.TextAlignment.Vertical := tlCenter;
  141. {$ifdef ColorBands}
  142. // just so the text is visible in this situation
  143. Memo.Frame.Shape := fsRectangle;
  144. Memo.Frame.BackgroundColor := clNavy;
  145. {$endif}
  146. DataBand := TFPReportDataBand.Create(p);
  147. DataBand.Layout.Height := 8;
  148. DataBand.Data := lReportData;
  149. {$ifdef ColorBands}
  150. DataBand.Frame.Shape := fsRectangle;
  151. DataBand.Frame.BackgroundColor := clDataBand;
  152. {$endif}
  153. Memo := TFPReportMemo.Create(DataBand);
  154. Memo.Layout.Left := 15;
  155. Memo.Layout.Top := 0;
  156. Memo.Layout.Width := 50;
  157. Memo.Layout.Height := 5;
  158. Memo.Text := '[country]';
  159. Memo.TextAlignment.Vertical := tlCenter;
  160. Memo := TFPReportMemo.Create(DataBand);
  161. Memo.Layout.Left := 70;
  162. Memo.Layout.Top := 0;
  163. Memo.Layout.Width := 30;
  164. Memo.Layout.Height := 5;
  165. Memo.Text := '[formatfloat(''#,##0'', StrToFloat(population))]';
  166. Memo.TextAlignment.Vertical := tlCenter;
  167. Memo.TextAlignment.Horizontal := taRightJustified;
  168. Checkbox := TFPReportCheckbox.Create(DataBand);
  169. Checkbox.Layout.Left := 120;
  170. Checkbox.Layout.Top := 1;
  171. Checkbox.Expression := '[population] > 30000000';
  172. PageFooter := TFPReportPageFooterBand.Create(p);
  173. PageFooter.Layout.Height := 30;
  174. {$ifdef ColorBands}
  175. PageFooter.Frame.Shape := fsRectangle;
  176. PageFooter.Frame.BackgroundColor := clPageHeaderFooter;
  177. {$endif}
  178. Memo := TFPReportMemo.Create(PageFooter);
  179. Memo.Layout.Left := 130;
  180. Memo.Layout.Top := 20;
  181. Memo.Layout.Width := 20;
  182. Memo.Layout.Height := 5;
  183. Memo.Text := 'Page [PageNo]';
  184. Memo.TextAlignment.Vertical := tlBottom;
  185. Memo.TextAlignment.Horizontal := taRightJustified;
  186. Image := TFPReportImage.Create(PageFooter);
  187. Image.Layout.Left := 0;
  188. Image.Layout.Top := 0;
  189. Image.Layout.Width := 40;
  190. Image.Layout.Height := 30;
  191. Image.LoadFromFile('company-logo.png');
  192. Image.Stretched := True;
  193. end;
  194. constructor TImagesDemo.Create(AOwner : TComponent);
  195. begin
  196. Inherited;
  197. lReportData := TFPReportUserData.Create(Self);
  198. lReportData.OnGetValue := @GetReportDataValue;
  199. lReportData.OnGetEOF := @GetReportDataEOF;
  200. lReportData.OnGetNames := @GetReportDataNames;
  201. end;
  202. destructor TImagesDemo.Destroy;
  203. begin
  204. FreeAndNil(lReportData);
  205. FreeAndNil(sl);
  206. inherited Destroy;
  207. end;
  208. class function TImagesDemo.Description: string;
  209. begin
  210. Result:='Demo showing image support';
  211. end;
  212. procedure TImagesDemo.GetReportDataNames(Sender: TObject; List: TStrings);
  213. begin
  214. List.Add('country');
  215. List.Add('population');
  216. end;
  217. end.