Recent

Author Topic: Dynamic grouping with LazReport  (Read 1704 times)

alessandrodidi

  • New member
  • *
  • Posts: 9
Dynamic grouping with LazReport
« on: February 17, 2022, 06:31:56 pm »
Hi community

I'm developing a report in LazReport in which I would like to dynamically create groupings at runtime so that the user can select which fields and in what order he wants to do the groupings.

I'm trying to do it like this:
In a ready-made report I'm trying to create a band of type Group Header and a Memo to show the grouping field. I'm implementing this in a button.
The memo is returning the value correctly, however I am not able to get the band to be created or to work correctly.


Here's my code below:

Code: Pascal  [Select][+][-]
  1. procedure TfrmRelatorios.Button1Click(Sender: TObject);
  2. var
  3.   Band: TfrBand;
  4.   Memo: TfrMemoView;
  5. begin
  6.   try
  7.     frReport1.LoadFromFile(Application.Location + 'Reports\RelEntregas.lrf');
  8.  
  9.     Band := TfrBand.Create(btGroupHeader, frReport1.Pages.Pages[0]);
  10.     Band.CreateUniqueName;
  11.     Band.DataSet := frReport1.Dataset;
  12.     Band.GroupCondition := 'sqlqRelatorio."EMPRESA"';
  13.     Band.Top := 89;
  14.     Band.Left := 0;
  15.     Band.Height := 22;
  16.     Band.Width := 752;
  17.     Band.Visible := True;
  18.  
  19.     Memo := TfrMemoView.Create(frReport1.Pages.Pages[0]);
  20.     Memo.Parent := Band;
  21.     Memo.ParentBandType := btMasterData;
  22.     Memo.CreateUniqueName;
  23.     Memo.Memo.Add('[sqlqRelatorio."EMPRESA"]');
  24.     Memo.Top := Band.Top+2;
  25.     Memo.Height := 18;
  26.     Memo.Width := 200;
  27.     Memo.Left := 20;
  28.     Memo.Font.Size := 9;
  29.     Memo.Font.Style := [fsBold];
  30.  
  31.     frReport1.ShowReport;
  32.  
  33.   except on E: exception do
  34.     begin
  35.       Application.MessageBox(PChar('Erro ao tentar gerar o relatório'+#13#13
  36.                                   +'Classe '+E.ClassName+#13
  37.                                   +'Detalhes: '+E.Message)
  38.                             ,'Erro',MB_ICONERROR + MB_OK);
  39.       Abort;
  40.     end;
  41.   end;
  42. end;
  43.  

PS. It's not generating any error, however the band isn't being created or something is missing to create the groups in the report.
PS2. Let me know if there's an easier way to do what I'm looking for.

A hug Lazarus community

gucao

  • New Member
  • *
  • Posts: 37
Re: Dynamic grouping with LazReport
« Reply #1 on: February 18, 2022, 03:09:33 pm »
is this?
Please give me more patience with my poor English

alessandrodidi

  • New member
  • *
  • Posts: 9
Re: Dynamic grouping with LazReport
« Reply #2 on: February 21, 2022, 03:41:48 pm »
Hi gucao.

Thanks for helping me with my problem.
Thanks to your tip I was able to develop the report the way I was thinking.
When I opened your code I realized that I was using the wrong object type to create the band and that's why it didn't show up in the report.
I was using TfrBand type when I should be using TfrBandView type.

tks.

 

TinyPortal © 2005-2018