rptnestedgroups.pp 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206
  1. unit rptnestedgroups;
  2. {$mode objfpc}{$H+}
  3. {$I demos.inc}
  4. interface
  5. uses
  6. Classes,
  7. SysUtils,
  8. fpreport,
  9. udapp;
  10. type
  11. { TNestedGroupsDemo }
  12. TNestedGroupsDemo = class(TReportDemoApp)
  13. private
  14. FReportData: TFPReportUserData;
  15. sl: TStringList;
  16. rec: TStringList;
  17. procedure GetReportDataFirst(Sender: TObject);
  18. procedure GetReportDataValue(Sender: TObject; const AValueName: String; var AValue: Variant);
  19. procedure GetReportDataEOF(Sender: TObject; var IsEOF: Boolean);
  20. procedure GetReportFieldNames(Sender: TObject; List: TStrings);
  21. procedure ReportDataNext(Sender: TObject);
  22. procedure PrepareRecord;
  23. Protected
  24. procedure InitialiseData; override;
  25. procedure CreateReportDesign;override;
  26. procedure LoadDesignFromFile(const AFilename: string);
  27. procedure HookupData(const AComponentName: string; const AData: TFPReportData);
  28. public
  29. constructor Create(AOWner :TComponent); override;
  30. destructor Destroy; override;
  31. Class function Description : string; override;
  32. end;
  33. implementation
  34. uses
  35. fpReportStreamer,
  36. fpTTF,
  37. fpJSON,
  38. jsonparser,
  39. fpexprpars;
  40. const
  41. clGroupHeaderFooter2 = TFPReportColor($EFE1C7);
  42. clGroupHeaderFooter3 = TFPReportColor($DFD1B7);
  43. { TNestedGroupsDemo }
  44. procedure TNestedGroupsDemo.GetReportDataFirst(Sender: TObject);
  45. begin
  46. {$IFDEF gdebug}
  47. writeln('GetReportDataFirst');
  48. {$ENDIF}
  49. PrepareRecord;
  50. end;
  51. procedure TNestedGroupsDemo.GetReportDataValue(Sender: TObject; const AValueName: String; var AValue: Variant);
  52. begin
  53. {$IFDEF gdebug}
  54. writeln(Format('GetReportDataValue - %d', [lReportData.RecNo]));
  55. {$ENDIF}
  56. case AValueName of
  57. 'region': AValue := rec[0];
  58. 'subregion': AValue := rec[1];
  59. 'country': AValue := rec[2];
  60. 'code': AValue := rec[3];
  61. 'population': AValue := rec[4];
  62. end;
  63. end;
  64. procedure TNestedGroupsDemo.GetReportDataEOF(Sender: TObject; var IsEOF: Boolean);
  65. begin
  66. {$IFDEF gdebug}
  67. writeln(Format('GetReportDataEOF - %d', [lReportData.RecNo]));
  68. {$ENDIF}
  69. if FReportData.RecNo > sl.Count then
  70. IsEOF := True
  71. else
  72. IsEOF := False;
  73. end;
  74. procedure TNestedGroupsDemo.GetReportFieldNames(Sender: TObject; List: TStrings);
  75. begin
  76. {$IFDEF gdebug}
  77. writeln('********** GetReportFieldNames');
  78. {$ENDIF}
  79. List.Add('region');
  80. List.Add('subregion');
  81. List.Add('country');
  82. List.Add('code');
  83. List.Add('population');
  84. end;
  85. procedure TNestedGroupsDemo.ReportDataNext(Sender: TObject);
  86. begin
  87. PrepareRecord;
  88. end;
  89. procedure TNestedGroupsDemo.PrepareRecord;
  90. begin
  91. if FReportData.RecNo > sl.Count then
  92. exit;
  93. rec.DelimitedText := sl[FReportData.RecNo-1];
  94. end;
  95. procedure TNestedGroupsDemo.InitialiseData;
  96. begin
  97. sl := TStringList.Create;
  98. {$I countries2.inc}
  99. rec := TStringList.Create;
  100. rec.Delimiter := ';';
  101. rec.StrictDelimiter := true;
  102. end;
  103. procedure TNestedGroupsDemo.CreateReportDesign;
  104. var
  105. Page: TFPReportPage;
  106. TitleBand: TFPReportTitleBand;
  107. DataBand: TFPReportDataBand;
  108. GroupHeader1Region, GroupHeader2Subregion, GroupHeader3Initial: TFPReportGroupHeaderBand;
  109. Memo: TFPReportMemo;
  110. PageFooter: TFPReportPageFooterBand;
  111. GroupFooter3Initial, GroupFooter2SubRegion, GroupFooter1Region: TFPReportGroupFooterBand;
  112. ChildBand: TFPReportChildBand;
  113. Shape: TFPReportShape;
  114. begin
  115. Inherited;
  116. rpt.Author := 'Pascal Riekenberg';
  117. rpt.Title := 'FPReport Demo 13 - Nested Grouping';
  118. {****************}
  119. {*** page ***}
  120. {****************}
  121. Page := TFPReportPage.Create(rpt);
  122. Page.Orientation := poPortrait;
  123. Page.PageSize.PaperName := 'A4';
  124. { page margins }
  125. Page.Margins.Left := 25;
  126. Page.Margins.Top := 20;
  127. Page.Margins.Right := 10;
  128. Page.Margins.Bottom := 20;
  129. Page.Data := FReportData;
  130. Page.Font.Name := 'LiberationSans';
  131. {*****************}
  132. {*** title ***}
  133. {*****************}
  134. TitleBand := TFPReportTitleBand.Create(Page);
  135. TitleBand.Layout.Height := 40;
  136. TitleBand.Frame.Shape := fsRectangle;
  137. TitleBand.Frame.BackgroundColor := clReportTitleSummary;
  138. Memo := TFPReportMemo.Create(TitleBand);
  139. Memo.Layout.Left := 0;
  140. Memo.Layout.Top := 10;
  141. Memo.Layout.Width := Page.PageSize.Width - Page.Margins.Left - Page.Margins.Right;
  142. Memo.Layout.Height := 16;
  143. Memo.TextAlignment.Horizontal := taCentered;
  144. Memo.UseParentFont := False;
  145. Memo.Text := 'COUNTRY AND POPULATION AS OF 2016';
  146. Memo.Font.Size := 16;
  147. Memo := TFPReportMemo.Create(TitleBand);
  148. Memo.Layout.Left := 0;
  149. Memo.Layout.Top := 18;
  150. Memo.Layout.Width := Page.PageSize.Width - Page.Margins.Left - Page.Margins.Right;
  151. Memo.Layout.Height := 10;
  152. Memo.TextAlignment.Horizontal := taCentered;
  153. Memo.UseParentFont := False;
  154. Memo.Text := '(Total [formatfloat(''#,##0.0'',total_sum_population_in_M / 1000)] B)';
  155. Memo.Font.Size := 10;
  156. {**********************}
  157. {*** group header ***}
  158. {**********************}
  159. {*** group header 1 region ***}
  160. {--- group header 1 region - band 1 ---}
  161. GroupHeader1Region := TFPReportGroupHeaderBand.Create(Page);
  162. GroupHeader1Region.Layout.Height := 15;
  163. GroupHeader1Region.GroupCondition := 'region';
  164. GroupHeader1Region.Frame.Shape := fsRectangle;
  165. GroupHeader1Region.Frame.BackgroundColor := clGroupHeaderFooter;
  166. //GroupHeader1Region.StartOnNewPage := True;
  167. GroupHeader1Region.ReprintedHeader := [rsPage];
  168. GroupHeader1Region.IntermediateFooter := [rsPage];
  169. //GroupHeader1Region.FooterPosition := fpStackAtBottom;
  170. GroupHeader1Region.VisibleExpr := 'not InRepeatedGroupHeader';
  171. Memo := TFPReportMemo.Create(GroupHeader1Region);
  172. Memo.Layout.Left := 3;
  173. Memo.Layout.Top := 1;
  174. Memo.Layout.Width := 170;
  175. Memo.Layout.Height := 6;
  176. Memo.UseParentFont := False;
  177. Memo.Font.Size := 16;
  178. Memo.TextAlignment.Vertical := tlBottom;
  179. Memo.Text := 'Region: [region] ([formatfloat(''#,##0.0'', grp1region_sum_population_in_M)] M)';
  180. Memo := TFPReportMemo.Create(GroupHeader1Region);
  181. Memo.Layout.Left := 25;
  182. Memo.Layout.Top := 1;
  183. Memo.Layout.Width := 145;
  184. Memo.Layout.Height := 6;
  185. Memo.UseParentFont := False;
  186. Memo.Font.Size := 10;
  187. Memo.TextAlignment.Vertical := tlBottom;
  188. Memo.TextAlignment.Horizontal := taRightJustified;
  189. Memo.Text := '[formatfloat(''#0.0'', grp1region_sum_population / total_sum_population * 100)] % in World';
  190. ChildBand := TFPReportChildBand.Create(Page);
  191. ChildBand.Layout.Height := 7;
  192. ChildBand.VisibleExpr := 'InRepeatedGroupHeader';
  193. ChildBand.Frame.Shape := fsRectangle;
  194. ChildBand.Frame.BackgroundColor := clGroupHeaderFooter;
  195. GroupHeader1Region.ChildBand := ChildBand;
  196. Memo := TFPReportMemo.Create(ChildBand);
  197. Memo.Layout.Left := 3;
  198. Memo.Layout.Top := 1;
  199. Memo.Layout.Width := 170;
  200. Memo.Layout.Height := 4;
  201. Memo.Text := 'Region: [region]';
  202. {*** group header 2 subregion ***}
  203. {--- group header 2 subregion - band 1 ---}
  204. GroupHeader2Subregion := TFPReportGroupHeaderBand.Create(Page);
  205. GroupHeader2Subregion.Layout.Height := 2;
  206. GroupHeader2Subregion.GroupCondition := 'subregion';
  207. GroupHeader2Subregion.ParentGroupHeader := GroupHeader1Region;
  208. //GroupHeader2Subregion.StartOnNewPage := True;
  209. GroupHeader2Subregion.ReprintedHeader := [rsPage];
  210. GroupHeader2Subregion.IntermediateFooter := [rsPage];
  211. //GroupHeader2Subregion.FooterPosition := fpStackAtBottom;
  212. Shape := TFPReportShape.Create(GroupHeader2Subregion);
  213. Shape.Color := clGroupHeaderFooter;
  214. Shape.Layout.Left := 0;
  215. Shape.Layout.Top := 0;
  216. Shape.Layout.Width := 3;
  217. Shape.Layout.Height := GroupHeader2Subregion.Layout.Height;
  218. Shape.Frame.Shape := fsRectangle;
  219. Shape.Frame.BackgroundColor := clGroupHeaderFooter;
  220. {--- group header 2 subregion - band 2 ---}
  221. ChildBand := TFPReportChildBand.Create(Page);
  222. ChildBand.Layout.Height := 15;
  223. ChildBand.Frame.Shape := fsRectangle;
  224. ChildBand.Frame.BackgroundColor := clGroupHeaderFooter2;
  225. ChildBand.VisibleExpr := 'not InRepeatedGroupHeader';
  226. GroupHeader2Subregion.ChildBand := ChildBand;
  227. Shape := TFPReportShape.Create(ChildBand);
  228. Shape.Color := clGroupHeaderFooter;
  229. Shape.Layout.Left := 0;
  230. Shape.Layout.Top := 0;
  231. Shape.Layout.Width := 3;
  232. Shape.Layout.Height := ChildBand.Layout.Height;
  233. Shape.Frame.Shape := fsRectangle;
  234. Shape.Frame.BackgroundColor := clGroupHeaderFooter;
  235. Shape := TFPReportShape.Create(ChildBand);
  236. Shape.Color := clNone;
  237. Shape.Layout.Left := 3;
  238. Shape.Layout.Top := 0;
  239. Shape.Layout.Width := 2;
  240. Shape.Layout.Height := ChildBand.Layout.Height;
  241. Shape.Frame.Shape := fsRectangle;
  242. Shape.Frame.BackgroundColor := clWhite;
  243. Memo := TFPReportMemo.Create(ChildBand);
  244. Memo.Layout.Left := 7;
  245. Memo.Layout.Top := 1;
  246. Memo.Layout.Width := 170;
  247. Memo.Layout.Height := 6;
  248. Memo.UseParentFont := False;
  249. Memo.Font.Size := 14;
  250. Memo.TextAlignment.Vertical := tlBottom;
  251. Memo.Text := 'Subregion: [subregion] ([formatfloat(''#,##0.0'', grp2subregion_sum_population_in_M)] M)';
  252. Memo := TFPReportMemo.Create(ChildBand);
  253. Memo.Layout.Left := 25;
  254. Memo.Layout.Top := 1;
  255. Memo.Layout.Width := 145;
  256. Memo.Layout.Height := 6;
  257. Memo.UseParentFont := False;
  258. Memo.Font.Size := 10;
  259. Memo.TextAlignment.Vertical := tlBottom;
  260. Memo.TextAlignment.Horizontal := taRightJustified;
  261. Memo.Text := '[formatfloat(''#0.0'', grp2subregion_sum_population / grp1region_sum_population * 100)] % in [region] - [formatfloat(''#0.0'', grp2subregion_sum_population / total_sum_population * 100)] % in World';
  262. {--- group header 2 subregion - band 3 ---}
  263. ChildBand := TFPReportChildBand.Create(Page);
  264. ChildBand.Layout.Height := 7;
  265. ChildBand.VisibleExpr := 'InRepeatedGroupHeader';
  266. ChildBand.Frame.Shape := fsRectangle;
  267. ChildBand.Frame.BackgroundColor := clGroupHeaderFooter2;
  268. GroupHeader2Subregion.ChildBand.ChildBand := ChildBand;
  269. Shape := TFPReportShape.Create(ChildBand);
  270. Shape.Color := clGroupHeaderFooter;
  271. Shape.Layout.Left := 0;
  272. Shape.Layout.Top := 0;
  273. Shape.Layout.Width := 3;
  274. Shape.Layout.Height := ChildBand.Layout.Height;
  275. Shape.Frame.Shape := fsRectangle;
  276. Shape.Frame.BackgroundColor := clGroupHeaderFooter;
  277. Shape := TFPReportShape.Create(ChildBand);
  278. Shape.Color := clNone;
  279. Shape.Layout.Left := 3;
  280. Shape.Layout.Top := 0;
  281. Shape.Layout.Width := 2;
  282. Shape.Layout.Height := ChildBand.Layout.Height;
  283. Shape.Frame.Shape := fsRectangle;
  284. Shape.Frame.BackgroundColor := clWhite;
  285. Memo := TFPReportMemo.Create(ChildBand);
  286. Memo.Layout.Left := 7;
  287. Memo.Layout.Top := 1;
  288. Memo.Layout.Width := 170;
  289. Memo.Layout.Height := 4;
  290. Memo.Text := 'Subregion: [subregion]';
  291. {*** group header 3 initial ***}
  292. {--- group header 3 initial - band 1 ---}
  293. GroupHeader3Initial := TFPReportGroupHeaderBand.Create(Page);
  294. GroupHeader3Initial.Layout.Height := 2;
  295. GroupHeader3Initial.GroupCondition := 'copy(country,1,1)';
  296. GroupHeader3Initial.ParentGroupHeader := GroupHeader2Subregion;
  297. GroupHeader3Initial.ReprintedHeader := [rsPage];
  298. GroupHeader3Initial.IntermediateFooter := [rsPage];
  299. //GroupHeader3Initial.OverflowedFooterNeedsReprintedHeader := True;
  300. Shape := TFPReportShape.Create(GroupHeader3Initial);
  301. Shape.Color := clGroupHeaderFooter;
  302. Shape.Layout.Left := 0;
  303. Shape.Layout.Top := 0;
  304. Shape.Layout.Width := 3;
  305. Shape.Layout.Height := GroupHeader3Initial.Layout.Height;
  306. Shape.Frame.Shape := fsRectangle;
  307. Shape.Frame.BackgroundColor := clGroupHeaderFooter;
  308. Shape := TFPReportShape.Create(GroupHeader3Initial);
  309. Shape.Color := clGroupHeaderFooter2;
  310. Shape.Layout.Left := 5;
  311. Shape.Layout.Top := 0;
  312. Shape.Layout.Width := 3;
  313. Shape.Layout.Height := GroupHeader3Initial.Layout.Height;
  314. Shape.Frame.Shape := fsRectangle;
  315. Shape.Frame.BackgroundColor := clGroupHeaderFooter2;
  316. {--- group header 3 initial - band 2 ---}
  317. ChildBand := TFPReportChildBand.Create(Page);
  318. ChildBand.Layout.Height := 15;
  319. ChildBand.Frame.Shape := fsRectangle;
  320. ChildBand.Frame.BackgroundColor := clGroupHeaderFooter3;
  321. ChildBand.VisibleExpr := 'not InRepeatedGroupHeader';
  322. GroupHeader3Initial.ChildBand := ChildBand;
  323. Shape := TFPReportShape.Create(ChildBand);
  324. Shape.Color := clGroupHeaderFooter;
  325. Shape.Layout.Left := 0;
  326. Shape.Layout.Top := 0;
  327. Shape.Layout.Width := 3;
  328. Shape.Layout.Height := ChildBand.Layout.Height;
  329. Shape.Frame.Shape := fsRectangle;
  330. Shape.Frame.BackgroundColor := clGroupHeaderFooter;
  331. Shape := TFPReportShape.Create(ChildBand);
  332. Shape.Color := clNone;
  333. Shape.Layout.Left := 3;
  334. Shape.Layout.Top := 0;
  335. Shape.Layout.Width := 2;
  336. Shape.Layout.Height := ChildBand.Layout.Height;
  337. Shape.Frame.Shape := fsRectangle;
  338. Shape.Frame.BackgroundColor := clWhite;
  339. Shape := TFPReportShape.Create(ChildBand);
  340. Shape.Color := clGroupHeaderFooter2;
  341. Shape.Layout.Left := 5;
  342. Shape.Layout.Top := 0;
  343. Shape.Layout.Width := 3;
  344. Shape.Layout.Height := ChildBand.Layout.Height;
  345. Shape.Frame.Shape := fsRectangle;
  346. Shape.Frame.BackgroundColor := clGroupHeaderFooter2;
  347. Shape := TFPReportShape.Create(ChildBand);
  348. Shape.Color := clNone;
  349. Shape.Layout.Left := 8;
  350. Shape.Layout.Top := 0;
  351. Shape.Layout.Width := 2;
  352. Shape.Layout.Height := ChildBand.Layout.Height;
  353. Shape.Frame.Shape := fsRectangle;
  354. Shape.Frame.BackgroundColor := clWhite;
  355. Memo := TFPReportMemo.Create(ChildBand);
  356. Memo.Layout.Left := 12;
  357. Memo.Layout.Top := 1;
  358. Memo.Layout.Width := 170;
  359. Memo.Layout.Height := 6;
  360. Memo.UseParentFont := False;
  361. Memo.Font.Size := 12;
  362. Memo.TextAlignment.Vertical := tlBottom;
  363. Memo.Text := '[copy(country,1,1)] ([formatfloat(''#,##0.0'', grp3initial_sum_population_in_M)] M)';
  364. Memo := TFPReportMemo.Create(ChildBand);
  365. Memo.Layout.Left := 25;
  366. Memo.Layout.Top := 1;
  367. Memo.Layout.Width := 145;
  368. Memo.Layout.Height := 6;
  369. Memo.UseParentFont := False;
  370. Memo.Font.Size := 10;
  371. Memo.TextAlignment.Vertical := tlBottom;
  372. Memo.TextAlignment.Horizontal := taRightJustified;
  373. Memo.Text := '[formatfloat(''#0.0'', grp3initial_sum_population / grp2subregion_sum_population * 100)] % in [subregion] - [formatfloat(''#0.0'', grp3initial_sum_population / grp1region_sum_population * 100)] % in [region] - [formatfloat(''#0.0'', grp3initial_sum_population / total_sum_population * 100)] % in World';
  374. Memo := TFPReportMemo.Create(ChildBand);
  375. Memo.Layout.Left := 90;
  376. Memo.Layout.Top := 10.5;
  377. Memo.Layout.Width := 20;
  378. Memo.Layout.Height := 4;
  379. Memo.TextAlignment.Horizontal := taRightJustified;
  380. Memo.Text := 'Initial %';
  381. Memo := TFPReportMemo.Create(ChildBand);
  382. Memo.Layout.Left := 110;
  383. Memo.Layout.Top := 10.5;
  384. Memo.Layout.Width := 20;
  385. Memo.Layout.Height := 4;
  386. Memo.TextAlignment.Horizontal := taRightJustified;
  387. Memo.Text := 'Subreg. %';
  388. Memo := TFPReportMemo.Create(ChildBand);
  389. Memo.Layout.Left := 130;
  390. Memo.Layout.Top := 10.5;
  391. Memo.Layout.Width := 20;
  392. Memo.Layout.Height := 4;
  393. Memo.TextAlignment.Horizontal := taRightJustified;
  394. Memo.Text := 'Region %';
  395. Memo := TFPReportMemo.Create(ChildBand);
  396. Memo.Layout.Left := 150;
  397. Memo.Layout.Top := 10.5;
  398. Memo.Layout.Width := 20;
  399. Memo.Layout.Height := 4;
  400. Memo.TextAlignment.Horizontal := taRightJustified;
  401. Memo.Text := 'World %';
  402. {--- group header 3 initial - band 3 ---}
  403. ChildBand := TFPReportChildBand.Create(Page);
  404. ChildBand.Layout.Height := 7;
  405. ChildBand.VisibleExpr := 'InRepeatedGroupHeader';
  406. ChildBand.Frame.Shape := fsRectangle;
  407. ChildBand.Frame.BackgroundColor := clGroupHeaderFooter3;
  408. GroupHeader3Initial.ChildBand.ChildBand := ChildBand;
  409. Shape := TFPReportShape.Create(ChildBand);
  410. Shape.Color := clGroupHeaderFooter;
  411. Shape.Layout.Left := 0;
  412. Shape.Layout.Top := 0;
  413. Shape.Layout.Width := 3;
  414. Shape.Layout.Height := ChildBand.Layout.Height;
  415. Shape.Frame.Shape := fsRectangle;
  416. Shape.Frame.BackgroundColor := clGroupHeaderFooter;
  417. Shape := TFPReportShape.Create(ChildBand);
  418. Shape.Color := clNone;
  419. Shape.Layout.Left := 3;
  420. Shape.Layout.Top := 0;
  421. Shape.Layout.Width := 2;
  422. Shape.Layout.Height := ChildBand.Layout.Height;
  423. Shape.Frame.Shape := fsRectangle;
  424. Shape.Frame.BackgroundColor := clWhite;
  425. Shape := TFPReportShape.Create(ChildBand);
  426. Shape.Color := clGroupHeaderFooter2;
  427. Shape.Layout.Left := 5;
  428. Shape.Layout.Top := 0;
  429. Shape.Layout.Width := 3;
  430. Shape.Layout.Height := ChildBand.Layout.Height;
  431. Shape.Frame.Shape := fsRectangle;
  432. Shape.Frame.BackgroundColor := clGroupHeaderFooter2;
  433. Shape := TFPReportShape.Create(ChildBand);
  434. Shape.Color := clNone;
  435. Shape.Layout.Left := 8;
  436. Shape.Layout.Top := 0;
  437. Shape.Layout.Width := 2;
  438. Shape.Layout.Height := ChildBand.Layout.Height;
  439. Shape.Frame.Shape := fsRectangle;
  440. Shape.Frame.BackgroundColor := clWhite;
  441. Memo := TFPReportMemo.Create(ChildBand);
  442. Memo.Layout.Left := 12;
  443. Memo.Layout.Top := 1;
  444. Memo.Layout.Width := 170;
  445. Memo.Layout.Height := 4;
  446. Memo.Text := '[copy(country,1,1)]';
  447. {--- group header 3 initial - band 4 ---}
  448. ChildBand := TFPReportChildBand.Create(Page);
  449. ChildBand.Layout.Height := 2;
  450. GroupHeader3Initial.ChildBand.ChildBand.ChildBand := ChildBand;
  451. Shape := TFPReportShape.Create(ChildBand);
  452. Shape.Color := clGroupHeaderFooter;
  453. Shape.Layout.Left := 0;
  454. Shape.Layout.Top := 0;
  455. Shape.Layout.Width := 3;
  456. Shape.Layout.Height := ChildBand.Layout.Height;
  457. Shape.Frame.Shape := fsRectangle;
  458. Shape.Frame.BackgroundColor := clGroupHeaderFooter;
  459. Shape := TFPReportShape.Create(ChildBand);
  460. Shape.Color := clGroupHeaderFooter2;
  461. Shape.Layout.Left := 5;
  462. Shape.Layout.Top := 0;
  463. Shape.Layout.Width := 3;
  464. Shape.Layout.Height := ChildBand.Layout.Height;
  465. Shape.Frame.Shape := fsRectangle;
  466. Shape.Frame.BackgroundColor := clGroupHeaderFooter2;
  467. Shape := TFPReportShape.Create(ChildBand);
  468. Shape.Color := clGroupHeaderFooter3;
  469. Shape.Layout.Left := 10;
  470. Shape.Layout.Top := 0;
  471. Shape.Layout.Width := 3;
  472. Shape.Layout.Height := ChildBand.Layout.Height;
  473. Shape.Frame.Shape := fsRectangle;
  474. Shape.Frame.BackgroundColor := clGroupHeaderFooter3;
  475. {*** variables ***}
  476. rpt.Variables.AddExprVariable('population_in_M', 'StrToFloat(population) / 1000000', rtFloat);
  477. rpt.Variables.AddExprVariable('grp1region_sum_population_in_M', 'sum(StrToFloat(population) / 1000000)', rtFloat, rtGroup, GroupHeader1Region);
  478. rpt.Variables.AddExprVariable('grp1region_sum_population', 'sum(StrToFloat(population))', rtFloat, rtGroup, GroupHeader1Region);
  479. rpt.Variables.AddExprVariable('grp2subregion_sum_population_in_M', 'sum(StrToFloat(population) / 1000000)', rtFloat, rtGroup, GroupHeader2Subregion);
  480. rpt.Variables.AddExprVariable('grp2subregion_sum_population', 'sum(StrToFloat(population))', rtFloat, rtGroup, GroupHeader2Subregion);
  481. rpt.Variables.AddExprVariable('grp3initial_sum_population_in_M', 'sum(StrToFloat(population) / 1000000)', rtFloat, rtGroup, GroupHeader3Initial);
  482. rpt.Variables.AddExprVariable('grp3initial_sum_population', 'sum(StrToFloat(population))', rtFloat, rtGroup, GroupHeader3Initial);
  483. rpt.Variables.AddExprVariable('total_sum_population_in_M', 'sum(StrToFloat(population) / 1000000)', rtFloat);
  484. rpt.Variables.AddExprVariable('total_sum_population', 'sum(StrToFloat(population))', rtFloat);
  485. {****************}
  486. {*** detail ***}
  487. {****************}
  488. DataBand := TFPReportDataBand.Create(Page);
  489. DataBand.Layout.Height := 8;
  490. DataBand.Frame.Shape := fsRectangle;
  491. DataBand.Frame.BackgroundColor := clDataBand;
  492. //DataBand.VisibleExpr := 'StrToFloat(''[population]'') > 50000000';
  493. Shape := TFPReportShape.Create(DataBand);
  494. Shape.Color := clGroupHeaderFooter;
  495. Shape.Layout.Left := 0;
  496. Shape.Layout.Top := 0;
  497. Shape.Layout.Width := 3;
  498. Shape.Layout.Height := DataBand.Layout.Height;
  499. Shape.Frame.Shape := fsRectangle;
  500. Shape.Frame.BackgroundColor := clGroupHeaderFooter;
  501. Shape := TFPReportShape.Create(DataBand);
  502. Shape.Color := clNone;
  503. Shape.Layout.Left := 3;
  504. Shape.Layout.Top := 0;
  505. Shape.Layout.Width := 2;
  506. Shape.Layout.Height := DataBand.Layout.Height;
  507. Shape.Frame.Shape := fsRectangle;
  508. Shape.Frame.BackgroundColor := clWhite;
  509. Shape := TFPReportShape.Create(DataBand);
  510. Shape.Color := clGroupHeaderFooter2;
  511. Shape.Layout.Left := 5;
  512. Shape.Layout.Top := 0;
  513. Shape.Layout.Width := 3;
  514. Shape.Layout.Height := DataBand.Layout.Height;
  515. Shape.Frame.Shape := fsRectangle;
  516. Shape.Frame.BackgroundColor := clGroupHeaderFooter2;
  517. Shape := TFPReportShape.Create(DataBand);
  518. Shape.Color := clNone;
  519. Shape.Layout.Left := 8;
  520. Shape.Layout.Top := 0;
  521. Shape.Layout.Width := 2;
  522. Shape.Layout.Height := DataBand.Layout.Height;
  523. Shape.Frame.Shape := fsRectangle;
  524. Shape.Frame.BackgroundColor := clWhite;
  525. Shape := TFPReportShape.Create(DataBand);
  526. Shape.Color := clGroupHeaderFooter3;
  527. Shape.Layout.Left := 10;
  528. Shape.Layout.Top := 0;
  529. Shape.Layout.Width := 3;
  530. Shape.Layout.Height := DataBand.Layout.Height;
  531. Shape.Frame.Shape := fsRectangle;
  532. Shape.Frame.BackgroundColor := clGroupHeaderFooter3;
  533. Shape := TFPReportShape.Create(DataBand);
  534. Shape.Color := clNone;
  535. Shape.Layout.Left := 13;
  536. Shape.Layout.Top := 0;
  537. Shape.Layout.Width := 2;
  538. Shape.Layout.Height := DataBand.Layout.Height;
  539. Shape.Frame.Shape := fsRectangle;
  540. Shape.Frame.BackgroundColor := clWhite;
  541. Memo := TFPReportMemo.Create(DataBand);
  542. Memo.Layout.Left := 17;
  543. Memo.Layout.Top := 2;
  544. Memo.Layout.Width := 45;
  545. Memo.Layout.Height := 5;
  546. Memo.Text := '[country]';
  547. Memo.Options := memo.Options + [moDisableWordWrap];
  548. Memo := TFPReportMemo.Create(DataBand);
  549. Memo.Layout.Left := 55;
  550. Memo.Layout.Top := 2;
  551. Memo.Layout.Width := 25;
  552. Memo.Layout.Height := 5;
  553. Memo.TextAlignment.Horizontal := taRightJustified;
  554. Memo.Text := '[formatfloat(''#,##0'', StrToFloat(population))]';
  555. Memo := TFPReportMemo.Create(DataBand);
  556. Memo.Layout.Left := 80;
  557. Memo.Layout.Top := 2;
  558. Memo.Layout.Width := 20;
  559. Memo.Layout.Height := 5;
  560. Memo.Text := '> DEU';
  561. Memo.UseParentFont := false;
  562. Memo.Font.Color := clGreen;
  563. Memo.VisibleExpr := 'StrToFloat(population) > 82667685';
  564. Memo := TFPReportMemo.Create(DataBand);
  565. Memo.Layout.Left := 80;
  566. Memo.Layout.Top := 2;
  567. Memo.Layout.Width := 20;
  568. Memo.Layout.Height := 5;
  569. Memo.Text := '< DEU';
  570. Memo.UseParentFont := false;
  571. Memo.Font.Color := clRed;
  572. Memo.VisibleExpr := 'StrToFloat(population) < 82667685';
  573. Memo := TFPReportMemo.Create(DataBand);
  574. Memo.Layout.Left := 95;
  575. Memo.Layout.Top := 2;
  576. Memo.Layout.Width := 15;
  577. Memo.Layout.Height := 5;
  578. Memo.TextAlignment.Horizontal := taRightJustified;
  579. Memo.Text := '[formatfloat(''#,##0.0'',StrToFloat(population)/grp3initial_sum_population*100)] %';
  580. Memo := TFPReportMemo.Create(DataBand);
  581. Memo.Layout.Left := 115;
  582. Memo.Layout.Top := 2;
  583. Memo.Layout.Width := 15;
  584. Memo.Layout.Height := 5;
  585. Memo.TextAlignment.Horizontal := taRightJustified;
  586. Memo.Text := '[formatfloat(''#,##0.0'',StrToFloat(population)/grp2subregion_sum_population*100)] %';
  587. Memo := TFPReportMemo.Create(DataBand);
  588. Memo.Layout.Left := 135;
  589. Memo.Layout.Top := 2;
  590. Memo.Layout.Width := 15;
  591. Memo.Layout.Height := 5;
  592. Memo.TextAlignment.Horizontal := taRightJustified;
  593. Memo.Text := '[formatfloat(''#,##0.0'',StrToFloat(population)/grp1region_sum_population*100)] %';
  594. Memo := TFPReportMemo.Create(DataBand);
  595. Memo.Layout.Left := 155;
  596. Memo.Layout.Top := 2;
  597. Memo.Layout.Width := 15;
  598. Memo.Layout.Height := 5;
  599. Memo.TextAlignment.Horizontal := taRightJustified;
  600. Memo.Text := '[formatfloat(''#,##0.0'',StrToFloat(population)/total_sum_population*100)] %';
  601. {**********************}
  602. {*** group footer ***}
  603. {**********************}
  604. {*** group footer 3 initial ***}
  605. {--- group footer 3 initial - band 1 ---}
  606. GroupFooter3Initial := TFPReportGroupFooterBand.Create(Page);
  607. GroupFooter3Initial.Layout.Height := 2;
  608. GroupFooter3Initial.GroupHeader := GroupHeader3Initial;
  609. GroupFooter3Initial.VisibleExpr := 'not IsOverflowed';
  610. Shape := TFPReportShape.Create(GroupFooter3Initial);
  611. Shape.Color := clGroupHeaderFooter;
  612. Shape.Layout.Left := 0;
  613. Shape.Layout.Top := 0;
  614. Shape.Layout.Width := 3;
  615. Shape.Layout.Height := GroupFooter3Initial.Layout.Height;
  616. Shape.Frame.Shape := fsRectangle;
  617. Shape.Frame.BackgroundColor := clGroupHeaderFooter;
  618. Shape := TFPReportShape.Create(GroupFooter3Initial);
  619. Shape.Color := clGroupHeaderFooter2;
  620. Shape.Layout.Left := 5;
  621. Shape.Layout.Top := 0;
  622. Shape.Layout.Width := 3;
  623. Shape.Layout.Height := GroupFooter3Initial.Layout.Height;
  624. Shape.Frame.Shape := fsRectangle;
  625. Shape.Frame.BackgroundColor := clGroupHeaderFooter2;
  626. Shape := TFPReportShape.Create(GroupFooter3Initial);
  627. Shape.Color := clGroupHeaderFooter3;
  628. Shape.Layout.Left := 10;
  629. Shape.Layout.Top := 0;
  630. Shape.Layout.Width := 3;
  631. Shape.Layout.Height := GroupFooter3Initial.Layout.Height;
  632. Shape.Frame.Shape := fsRectangle;
  633. Shape.Frame.BackgroundColor := clGroupHeaderFooter3;
  634. {--- group footer 3 initial - band 2 ---}
  635. ChildBand := TFPReportChildBand.Create(Page);
  636. ChildBand.Layout.Height := 2;
  637. ChildBand.VisibleExpr := 'IsOverflowed';
  638. GroupFooter3Initial.ChildBand := ChildBand;
  639. Shape := TFPReportShape.Create(ChildBand);
  640. Shape.Color := clGroupHeaderFooter;
  641. Shape.Layout.Left := 0;
  642. Shape.Layout.Top := 0;
  643. Shape.Layout.Width := 3;
  644. Shape.Layout.Height := ChildBand.Layout.Height;
  645. Shape.Frame.Shape := fsRectangle;
  646. Shape.Frame.BackgroundColor := clGroupHeaderFooter;
  647. Shape := TFPReportShape.Create(ChildBand);
  648. Shape.Color := clGroupHeaderFooter2;
  649. Shape.Layout.Left := 5;
  650. Shape.Layout.Top := 0;
  651. Shape.Layout.Width := 3;
  652. Shape.Layout.Height := ChildBand.Layout.Height;
  653. Shape.Frame.Shape := fsRectangle;
  654. Shape.Frame.BackgroundColor := clGroupHeaderFooter2;
  655. {--- group footer 3 initial - band 3 ---}
  656. ChildBand := TFPReportChildBand.Create(Page);
  657. ChildBand.Layout.Height := 15;
  658. ChildBand.Frame.Shape := fsRectangle;
  659. ChildBand.Frame.BackgroundColor := clGroupHeaderFooter3;
  660. ChildBand.VisibleExpr := 'not InIntermediateGroupFooter';
  661. GroupFooter3Initial.ChildBand.ChildBand := ChildBand;
  662. Shape := TFPReportShape.Create(ChildBand);
  663. Shape.Color := clGroupHeaderFooter;
  664. Shape.Layout.Left := 0;
  665. Shape.Layout.Top := 0;
  666. Shape.Layout.Width := 3;
  667. Shape.Layout.Height := ChildBand.Layout.Height;
  668. Shape.Frame.Shape := fsRectangle;
  669. Shape.Frame.BackgroundColor := clGroupHeaderFooter;
  670. Shape := TFPReportShape.Create(ChildBand);
  671. Shape.Color := clNone;
  672. Shape.Layout.Left := 3;
  673. Shape.Layout.Top := 0;
  674. Shape.Layout.Width := 2;
  675. Shape.Layout.Height := ChildBand.Layout.Height;
  676. Shape.Frame.Shape := fsRectangle;
  677. Shape.Frame.BackgroundColor := clWhite;
  678. Shape := TFPReportShape.Create(ChildBand);
  679. Shape.Color := clGroupHeaderFooter2;
  680. Shape.Layout.Left := 5;
  681. Shape.Layout.Top := 0;
  682. Shape.Layout.Width := 3;
  683. Shape.Layout.Height := ChildBand.Layout.Height;
  684. Shape.Frame.Shape := fsRectangle;
  685. Shape.Frame.BackgroundColor := clGroupHeaderFooter2;
  686. Shape := TFPReportShape.Create(ChildBand);
  687. Shape.Color := clNone;
  688. Shape.Layout.Left := 8;
  689. Shape.Layout.Top := 0;
  690. Shape.Layout.Width := 2;
  691. Shape.Layout.Height := ChildBand.Layout.Height;
  692. Shape.Frame.Shape := fsRectangle;
  693. Shape.Frame.BackgroundColor := clWhite;
  694. Memo := TFPReportMemo.Create(ChildBand);
  695. Memo.Layout.Left := 12;
  696. Memo.Layout.Top := 3;
  697. Memo.Layout.Width := 170;
  698. Memo.Layout.Height := 6;
  699. Memo.UseParentFont := False;
  700. Memo.Font.Size := 12;
  701. Memo.TextAlignment.Vertical := tlBottom;
  702. Memo.Text := 'Population [copy(country,1,1)]: [formatfloat(''#,##0'', grp3initial_sum_population)]';
  703. {--- group footer 3 initial - band 4 ---}
  704. ChildBand := TFPReportChildBand.Create(Page);
  705. ChildBand.Layout.Height := 3;
  706. ChildBand.Frame.Shape := fsRectangle;
  707. ChildBand.Frame.BackgroundColor := clGroupHeaderFooter3;
  708. ChildBand.VisibleExpr := 'InIntermediateGroupFooter';
  709. GroupFooter3Initial.ChildBand.ChildBand.ChildBand := ChildBand;
  710. Shape := TFPReportShape.Create(ChildBand);
  711. Shape.Color := clGroupHeaderFooter;
  712. Shape.Layout.Left := 0;
  713. Shape.Layout.Top := 0;
  714. Shape.Layout.Width := 3;
  715. Shape.Layout.Height := ChildBand.Layout.Height;
  716. Shape.Frame.Shape := fsRectangle;
  717. Shape.Frame.BackgroundColor := clGroupHeaderFooter;
  718. Shape := TFPReportShape.Create(ChildBand);
  719. Shape.Color := clNone;
  720. Shape.Layout.Left := 3;
  721. Shape.Layout.Top := 0;
  722. Shape.Layout.Width := 2;
  723. Shape.Layout.Height := ChildBand.Layout.Height;
  724. Shape.Frame.Shape := fsRectangle;
  725. Shape.Frame.BackgroundColor := clWhite;
  726. Shape := TFPReportShape.Create(ChildBand);
  727. Shape.Color := clGroupHeaderFooter2;
  728. Shape.Layout.Left := 5;
  729. Shape.Layout.Top := 0;
  730. Shape.Layout.Width := 3;
  731. Shape.Layout.Height := ChildBand.Layout.Height;
  732. Shape.Frame.Shape := fsRectangle;
  733. Shape.Frame.BackgroundColor := clGroupHeaderFooter2;
  734. Shape := TFPReportShape.Create(ChildBand);
  735. Shape.Color := clNone;
  736. Shape.Layout.Left := 8;
  737. Shape.Layout.Top := 0;
  738. Shape.Layout.Width := 2;
  739. Shape.Layout.Height := ChildBand.Layout.Height;
  740. Shape.Frame.Shape := fsRectangle;
  741. Shape.Frame.BackgroundColor := clWhite;
  742. {*** group footer 2 subregion ***}
  743. {--- group footer 2 subregion - band 1 ---}
  744. GroupFooter2SubRegion := TFPReportGroupFooterBand.Create(Page);
  745. GroupFooter2SubRegion.Layout.Height := 2;
  746. GroupFooter2SubRegion.GroupHeader := GroupHeader2Subregion;
  747. GroupFooter2SubRegion.VisibleExpr := '(not IsOverflowed) and (not InIntermediateGroupFooter)';
  748. Shape := TFPReportShape.Create(GroupFooter2SubRegion);
  749. Shape.Color := clGroupHeaderFooter;
  750. Shape.Layout.Left := 0;
  751. Shape.Layout.Top := 0;
  752. Shape.Layout.Width := 3;
  753. Shape.Layout.Height := GroupFooter2SubRegion.Layout.Height;
  754. Shape.Frame.Shape := fsRectangle;
  755. Shape.Frame.BackgroundColor := clGroupHeaderFooter;
  756. Shape := TFPReportShape.Create(GroupFooter2SubRegion);
  757. Shape.Color := clGroupHeaderFooter2;
  758. Shape.Layout.Left := 5;
  759. Shape.Layout.Top := 0;
  760. Shape.Layout.Width := 3;
  761. Shape.Layout.Height := GroupFooter2SubRegion.Layout.Height;
  762. Shape.Frame.Shape := fsRectangle;
  763. Shape.Frame.BackgroundColor := clGroupHeaderFooter2;
  764. {--- group footer 2 subregion - band 2 ---}
  765. ChildBand := TFPReportChildBand.Create(Page);
  766. ChildBand.Layout.Height := 2;
  767. ChildBand.VisibleExpr := 'IsOverflowed';
  768. GroupFooter2SubRegion.ChildBand := ChildBand;
  769. Shape := TFPReportShape.Create(ChildBand);
  770. Shape.Color := clGroupHeaderFooter;
  771. Shape.Layout.Left := 0;
  772. Shape.Layout.Top := 0;
  773. Shape.Layout.Width := 3;
  774. Shape.Layout.Height := ChildBand.Layout.Height;
  775. Shape.Frame.Shape := fsRectangle;
  776. Shape.Frame.BackgroundColor := clGroupHeaderFooter;
  777. {--- group footer 2 subregion - band 3 ---}
  778. ChildBand := TFPReportChildBand.Create(Page);
  779. ChildBand.Layout.Height := 15;
  780. ChildBand.Frame.Shape := fsRectangle;
  781. ChildBand.Frame.BackgroundColor := clGroupHeaderFooter2;
  782. ChildBand.VisibleExpr := 'not InIntermediateGroupFooter';
  783. GroupFooter2SubRegion.ChildBand.ChildBand := ChildBand;
  784. Shape := TFPReportShape.Create(ChildBand);
  785. Shape.Color := clGroupHeaderFooter;
  786. Shape.Layout.Left := 0;
  787. Shape.Layout.Top := 0;
  788. Shape.Layout.Width := 3;
  789. Shape.Layout.Height := ChildBand.Layout.Height;
  790. Shape.Frame.Shape := fsRectangle;
  791. Shape.Frame.BackgroundColor := clGroupHeaderFooter;
  792. Shape := TFPReportShape.Create(ChildBand);
  793. Shape.Color := clNone;
  794. Shape.Layout.Left := 3;
  795. Shape.Layout.Top := 0;
  796. Shape.Layout.Width := 2;
  797. Shape.Layout.Height := ChildBand.Layout.Height;
  798. Shape.Frame.Shape := fsRectangle;
  799. Shape.Frame.BackgroundColor := clWhite;
  800. Memo := TFPReportMemo.Create(ChildBand);
  801. Memo.Layout.Left := 7;
  802. Memo.Layout.Top := 3;
  803. Memo.Layout.Width := 170;
  804. Memo.Layout.Height := 6;
  805. Memo.UseParentFont := False;
  806. Memo.Font.Size := 14;
  807. Memo.TextAlignment.Vertical := tlBottom;
  808. Memo.Text := 'Population [subregion]: [formatfloat(''#,##0'', grp2subregion_sum_population)]';
  809. {--- group footer 2 subregion - band 4 ---}
  810. ChildBand := TFPReportChildBand.Create(Page);
  811. ChildBand.Layout.Height := 2;
  812. ChildBand.VisibleExpr := 'InIntermediateGroupFooter';
  813. GroupFooter2SubRegion.ChildBand.ChildBand.ChildBand := ChildBand;
  814. Shape := TFPReportShape.Create(ChildBand);
  815. Shape.Color := clGroupHeaderFooter;
  816. Shape.Layout.Left := 0;
  817. Shape.Layout.Top := 0;
  818. Shape.Layout.Width := 3;
  819. Shape.Layout.Height := ChildBand.Layout.Height;
  820. Shape.Frame.Shape := fsRectangle;
  821. Shape.Frame.BackgroundColor := clGroupHeaderFooter;
  822. Shape := TFPReportShape.Create(ChildBand);
  823. Shape.Color := clNone;
  824. Shape.Layout.Left := 5;
  825. Shape.Layout.Top := 0;
  826. Shape.Layout.Width := 3;
  827. Shape.Layout.Height := ChildBand.Layout.Height;
  828. Shape.Frame.Shape := fsRectangle;
  829. Shape.Frame.BackgroundColor := clGroupHeaderFooter2;
  830. {--- group footer 2 subregion - band 5 ---}
  831. ChildBand := TFPReportChildBand.Create(Page);
  832. ChildBand.Layout.Height := 3;
  833. ChildBand.VisibleExpr := 'InIntermediateGroupFooter';
  834. ChildBand.Frame.Shape := fsRectangle;
  835. ChildBand.Frame.BackgroundColor := clGroupHeaderFooter2;
  836. GroupFooter2SubRegion.ChildBand.ChildBand.ChildBand.ChildBand := ChildBand;
  837. Shape := TFPReportShape.Create(ChildBand);
  838. Shape.Color := clGroupHeaderFooter;
  839. Shape.Layout.Left := 0;
  840. Shape.Layout.Top := 0;
  841. Shape.Layout.Width := 3;
  842. Shape.Layout.Height := ChildBand.Layout.Height;
  843. Shape.Frame.Shape := fsRectangle;
  844. Shape.Frame.BackgroundColor := clGroupHeaderFooter;
  845. Shape := TFPReportShape.Create(ChildBand);
  846. Shape.Color := clNone;
  847. Shape.Layout.Left := 3;
  848. Shape.Layout.Top := 0;
  849. Shape.Layout.Width := 2;
  850. Shape.Layout.Height := ChildBand.Layout.Height;
  851. Shape.Frame.Shape := fsRectangle;
  852. Shape.Frame.BackgroundColor := clWhite;
  853. {*** group footer 1 region ***}
  854. {--- group footer 1 region - band 1 ---}
  855. GroupFooter1Region := TFPReportGroupFooterBand.Create(Page);
  856. GroupFooter1Region.Layout.Height := 2;
  857. GroupFooter1Region.GroupHeader := GroupHeader1Region;
  858. GroupFooter1Region.VisibleExpr := '(not IsOverflowed) and (not InIntermediateGroupFooter)';
  859. Shape := TFPReportShape.Create(GroupFooter1Region);
  860. Shape.Color := clGroupHeaderFooter;
  861. Shape.Layout.Left := 0;
  862. Shape.Layout.Top := 0;
  863. Shape.Layout.Width := 3;
  864. Shape.Layout.Height := GroupFooter1Region.Layout.Height;
  865. Shape.Frame.Shape := fsRectangle;
  866. Shape.Frame.BackgroundColor := clGroupHeaderFooter;
  867. {--- group footer 1 region - band 2 ---}
  868. ChildBand := TFPReportChildBand.Create(Page);
  869. ChildBand.Layout.Height := 15;
  870. ChildBand.VisibleExpr := 'not InIntermediateGroupFooter';
  871. ChildBand.Frame.Shape := fsRectangle;
  872. ChildBand.Frame.BackgroundColor := clGroupHeaderFooter;
  873. GroupFooter1Region.ChildBand := ChildBand;
  874. Memo := TFPReportMemo.Create(ChildBand);
  875. Memo.Layout.Left := 3;
  876. Memo.Layout.Top := 3;
  877. Memo.Layout.Width := 170;
  878. Memo.Layout.Height := 6;
  879. Memo.UseParentFont := False;
  880. Memo.Font.Size := 16;
  881. Memo.TextAlignment.Vertical := tlBottom;
  882. Memo.Text := 'Population [region]: [formatfloat(''#,##0'', grp1region_sum_population)]';
  883. {--- group footer 1 region - band 3 ---}
  884. ChildBand := TFPReportChildBand.Create(Page);
  885. ChildBand.Layout.Height := 2;
  886. ChildBand.VisibleExpr := 'not InIntermediateGroupFooter';
  887. GroupFooter1Region.ChildBand.ChildBand := ChildBand;
  888. {--- group footer 1 region - band 4 ---}
  889. ChildBand := TFPReportChildBand.Create(Page);
  890. ChildBand.Layout.Height := 2;
  891. ChildBand.VisibleExpr := 'InIntermediateGroupFooter';
  892. GroupFooter1Region.ChildBand.ChildBand.ChildBand := ChildBand;
  893. Shape := TFPReportShape.Create(ChildBand);
  894. Shape.Color := clGroupHeaderFooter;
  895. Shape.Layout.Left := 0;
  896. Shape.Layout.Top := 0;
  897. Shape.Layout.Width := 3;
  898. Shape.Layout.Height := ChildBand.Layout.Height;
  899. Shape.Frame.Shape := fsRectangle;
  900. Shape.Frame.BackgroundColor := clGroupHeaderFooter;
  901. {--- group footer 1 region - band 5 ---}
  902. ChildBand := TFPReportChildBand.Create(Page);
  903. ChildBand.Layout.Height := 3;
  904. ChildBand.VisibleExpr := 'InIntermediateGroupFooter';
  905. ChildBand.Frame.Shape := fsRectangle;
  906. ChildBand.Frame.BackgroundColor := clGroupHeaderFooter;
  907. GroupFooter1Region.ChildBand.ChildBand.ChildBand.ChildBand := ChildBand;
  908. {*******************}
  909. {*** page footer ***}
  910. {*******************}
  911. {--- page footer - band 1 ---}
  912. PageFooter := TFPReportPageFooterBand.Create(Page);
  913. PageFooter.Layout.Height := 20;
  914. PageFooter.Frame.Shape := fsRectangle;
  915. PageFooter.Frame.BackgroundColor := clPageHeaderFooter;
  916. Memo := TFPReportMemo.Create(PageFooter);
  917. Memo.Layout.Left := 123;
  918. Memo.Layout.Top := 13;
  919. Memo.Layout.Width := 50;
  920. Memo.Layout.Height := 5;
  921. Memo.Text := 'Page [PageNo] of [PageCount]';
  922. Memo.TextAlignment.Vertical := tlCenter;
  923. Memo.TextAlignment.Horizontal := taRightJustified;
  924. Memo := TFPReportMemo.Create(PageFooter);
  925. Memo.Layout.Left := 0;
  926. Memo.Layout.Top := 5;
  927. Memo.Layout.Width := Page.PageSize.Width - Page.Margins.Left - Page.Margins.Right;
  928. Memo.Layout.Height := 8;
  929. Memo.UseParentFont := False;
  930. Memo.TextAlignment.Horizontal := taCentered;
  931. Memo.Text := 'Population World: [formatfloat(''#,##0'', total_sum_population)]';
  932. Memo.Font.Size := 16;
  933. {--- page footer - band 2 ---}
  934. ChildBand := TFPReportChildBand.Create(Page);
  935. ChildBand.Layout.Height := 10;
  936. ChildBand.VisibleExpr := 'PageNo mod 2 = 0';
  937. ChildBand.Frame.Shape := fsRectangle;
  938. ChildBand.Frame.BackgroundColor := clChildBand;
  939. PageFooter.ChildBand := ChildBand;
  940. Memo := TFPReportMemo.Create(ChildBand);
  941. Memo.Layout.Left := 0;
  942. Memo.Layout.Top := 0;
  943. Memo.Layout.Width := Page.PageSize.Width - Page.Margins.Left - Page.Margins.Right;
  944. Memo.Layout.Height := 10;
  945. Memo.Text := 'even page: [pageno]';
  946. Memo.TextAlignment.Vertical := tlCenter;
  947. Memo.TextAlignment.Horizontal := taCentered;
  948. {--- page footer - band 3 ---}
  949. ChildBand := TFPReportChildBand.Create(Page);
  950. ChildBand.Layout.Height := 20;
  951. ChildBand.VisibleExpr := 'PageNo mod 5 = 0';
  952. ChildBand.Frame.Shape := fsRectangle;
  953. ChildBand.Frame.BackgroundColor := clReportTitleSummary;
  954. PageFooter.ChildBand.ChildBand := ChildBand;
  955. Memo := TFPReportMemo.Create(ChildBand);
  956. Memo.Layout.Left := 0;
  957. Memo.Layout.Top := 0;
  958. Memo.Layout.Width := Page.PageSize.Width - Page.Margins.Left - Page.Margins.Right;
  959. Memo.Layout.Height := 20;
  960. Memo.Text := 'multiple of 5: [pageno]';
  961. Memo.TextAlignment.Vertical := tlCenter;
  962. Memo.TextAlignment.Horizontal := taCentered;
  963. end;
  964. procedure TNestedGroupsDemo.LoadDesignFromFile(const AFilename: string);
  965. var
  966. rs: TFPReportJSONStreamer;
  967. fs: TFileStream;
  968. lJSON: TJSONObject;
  969. begin
  970. if AFilename = '' then
  971. Exit;
  972. if not FileExists(AFilename) then
  973. raise Exception.CreateFmt('The file "%s" can not be found', [AFilename]);
  974. fs := TFileStream.Create(AFilename, fmOpenRead or fmShareDenyNone);
  975. try
  976. lJSON := TJSONObject(GetJSON(fs));
  977. finally
  978. fs.Free;
  979. end;
  980. rs := TFPReportJSONStreamer.Create(nil);
  981. rs.JSON := lJSON; // rs takes ownership of lJSON
  982. try
  983. rpt.ReadElement(rs);
  984. finally
  985. rs.Free;
  986. end;
  987. end;
  988. procedure TNestedGroupsDemo.HookupData(const AComponentName: string; const AData: TFPReportData);
  989. var
  990. b: TFPReportCustomBandWithData;
  991. begin
  992. b := TFPReportCustomBandWithData(rpt.FindRecursive(AComponentName));
  993. if Assigned(b) then
  994. b.Data := AData;
  995. end;
  996. constructor TNestedGroupsDemo.Create(AOWner: TComponent);
  997. begin
  998. inherited;
  999. FReportData := TFPReportUserData.Create(nil);
  1000. FReportData.OnGetValue := @GetReportDataValue;
  1001. FReportData.OnGetEOF := @GetReportDataEOF;
  1002. FReportData.OnFirst := @GetReportDataFirst;
  1003. FReportData.OnGetNames := @GetReportFieldNames;
  1004. FReportData.OnNext := @ReportDataNext;
  1005. end;
  1006. destructor TNestedGroupsDemo.Destroy;
  1007. begin
  1008. FreeAndNil(FReportData);
  1009. rec.DelimitedText := '';
  1010. FreeAndNil(rec);
  1011. FreeAndNil(sl);
  1012. inherited Destroy;
  1013. end;
  1014. class function TNestedGroupsDemo.Description: string;
  1015. begin
  1016. Result:='Demo showing grouping';
  1017. end;
  1018. end.