rptnestedgroups.pp 40 KB

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