1unit rptsimplelist; 2 3 4{$mode objfpc}{$H+} 5{$I demos.inc} 6 7interface 8 9uses 10 Classes, 11 SysUtils, 12 fpreport, 13 udapp; 14 15type 16 17 { TSimpleListDemo } 18 19 TSimpleListDemo = class(TReportDemoApp) 20 private 21 lReportData: TFPReportUserData; 22 sl: TStringList; 23 procedure GetReportDataFirst(Sender: TObject); 24 procedure GetReportDataValue(Sender: TObject; const AValueName: String; var AValue: Variant); 25 procedure GetReportDataEOF(Sender: TObject; var IsEOF: Boolean); 26 procedure GetReportDataNames(Sender: TObject; List: TStrings); 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 fpTTF; 41 42{ TSimpleListDemo } 43 44procedure TSimpleListDemo.GetReportDataFirst(Sender: TObject); 45begin 46 {$IFDEF gdebug} 47 writeln('GetReportDataFirst'); 48 {$ENDIF} 49end; 50 51procedure TSimpleListDemo.GetReportDataValue(Sender: TObject; const AValueName: String; var AValue: Variant); 52begin 53 {$IFDEF gdebug} 54 writeln(Format('GetReportDataValue - %d', [lReportData.RecNo])); 55 {$ENDIF} 56 if AValueName = 'element' then 57 begin 58 AValue := sl[lReportData.RecNo-1]; 59 end; 60end; 61 62procedure TSimpleListDemo.GetReportDataEOF(Sender: TObject; var IsEOF: Boolean); 63begin 64 {$IFDEF gdebug} 65 writeln(Format('GetReportDataEOF - %d', [lReportData.RecNo])); 66 {$ENDIF} 67 if lReportData.RecNo > sl.Count then 68 IsEOF := True 69 else 70 IsEOF := False; 71end; 72 73procedure TSimpleListDemo.GetReportDataNames(Sender: TObject; List: TStrings); 74begin 75 List.Add('element'); 76end; 77 78procedure TSimpleListDemo.InitialiseData; 79var 80 i: integer; 81begin 82 sl := TStringList.Create; 83 for i := 1 to 30 do 84 sl.Add(Format('Item %d', [i])); 85end; 86 87procedure TSimpleListDemo.CreateReportDesign; 88var 89 p: TFPReportPage; 90 TitleBand: TFPReportTitleBand; 91 DataBand: TFPReportDataBand; 92 Memo: TFPReportMemo; 93 PageFooter: TFPReportPageFooterBand; 94 SummaryBand: TFPReportSummaryBand; 95begin 96 Inherited; 97 rpt.Author := 'Graeme Geldenhuys'; 98 rpt.Title := 'FPReport Demo 1 - Simple Listing'; 99 100 p := TFPReportPage.Create(rpt); 101 p.Orientation := poPortrait; 102 p.PageSize.PaperName := 'A4'; 103 { page margins } 104 p.Margins.Left := 30; 105 p.Margins.Top := 20; 106 p.Margins.Right := 30; 107 p.Margins.Bottom := 20; 108 p.Data := lReportData; 109 p.Font.Name := 'LiberationSans'; 110 111 TitleBand := TFPReportTitleBand.Create(p); 112 TitleBand.Layout.Height := 40; 113 {$ifdef ColorBands} 114 TitleBand.Frame.Shape := fsRectangle; 115 TitleBand.Frame.BackgroundColor := clReportTitleSummary; 116 {$endif} 117 118 Memo := TFPReportMemo.Create(TitleBand); 119 Memo.Layout.Left := 55; 120 Memo.Layout.Top := 20; 121 Memo.Layout.Width := 50; 122 Memo.Layout.Height := 10; 123 Memo.Text := 'THE REPORT TITLE'; 124 125 DataBand := TFPReportDataBand.Create(p); 126 DataBand.Layout.Height := 10; 127 {$ifdef ColorBands} 128 DataBand.Frame.Shape := fsRectangle; 129 DataBand.Frame.BackgroundColor := clDataBand; 130 {$endif} 131 132 Memo := TFPReportMemo.Create(DataBand); 133 Memo.Layout.Left := 5; 134 Memo.Layout.Top := 0; 135 Memo.Layout.Width := 60; 136 Memo.Layout.Height := 5; 137 Memo.Text := 'Hello world <[element]>.'; 138 139 PageFooter := TFPReportPageFooterBand.Create(p); 140 PageFooter.Layout.Height := 20; 141 {$ifdef ColorBands} 142 PageFooter.Frame.Shape := fsRectangle; 143 PageFooter.Frame.BackgroundColor := clPageHeaderFooter; 144 {$endif} 145 146 Memo := TFPReportMemo.Create(PageFooter); 147 Memo.Layout.Left := 135; 148 Memo.Layout.Top := 13; 149 Memo.Layout.Width := 20; 150 Memo.Layout.Height := 5; 151 Memo.Text := 'Page [PageNo]'; 152 153 154 SummaryBand := TFPReportSummaryBand.Create(p); 155 SummaryBand.Layout.Height := 40; 156 {$ifdef ColorBands} 157 SummaryBand.Frame.Shape := fsRectangle; 158 SummaryBand.Frame.BackgroundColor := clReportTitleSummary; 159 {$endif} 160 161 Memo := TFPReportMemo.Create(SummaryBand); 162 Memo.Layout.Left := 19; 163 Memo.Layout.Top := 10; 164 Memo.Layout.Width := 70; 165 Memo.Layout.Height := 25; 166 Memo.StretchMode := smActualHeight; 167 Memo.Text := 'This is some long text that should be wrapping inside the memo. It has a 10mm left margin, and a 7mm right margin. 0mm margin top and bottom.'; 168 Memo.TextAlignment.LeftMargin := 10; 169 Memo.TextAlignment.RightMargin := 7; 170 Memo.TextAlignment.Horizontal := taWidth; 171 Memo.Frame.Shape := fsRectangle; 172 Memo.Frame.BackgroundColor := clLtGray; 173end; 174 175constructor TSimpleListDemo.Create(AOwner : TComponent); 176begin 177 Inherited; 178 lReportData := TFPReportUserData.Create(Self); 179 lReportData.OnGetValue := @GetReportDataValue; 180 lReportData.OnGetEOF := @GetReportDataEOF; 181 lReportData.OnFirst := @GetReportDataFirst; 182 lReportData.OnGetNames := @GetReportDataNames; 183end; 184 185destructor TSimpleListDemo.Destroy; 186begin 187 FreeAndNil(lReportData); 188 FreeAndNil(sl); 189 inherited Destroy; 190end; 191 192class function TSimpleListDemo.Description: string; 193begin 194 Result:='Simple list of countries'; 195end; 196 197 198end. 199 200