rptshapes.pp 5.7 KB

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