rptshapes.pp 5.6 KB

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