* * *

Author Topic: fpreport: TFPReportUserData work not as expected  (Read 449 times)

af0815

  • Jr. Member
  • **
  • Posts: 68
fpreport: TFPReportUserData work not as expected
« on: April 26, 2018, 10:48:57 am »
I have the following code
Code: Pascal  [Select]
  1. ....
  2.   lReportData := TFPReportUserData.Create(Self);
  3.   lReportData.Name:='userdata';
  4.   lReportData.OnGetValue := @GetReportDataValue;
  5.   lReportData.OnGetEOF := @GetReportDataEOF;
  6.   lReportData.OnFirst := @GetReportDataFirst;
  7.   lReportData.OnGetNames := @GetReportDataNames;
  8.   lReportData.InitFieldDefs;
  9.   InitialiseData;
  10. ....
  11.   p := TFPReportPage.Create(FReport);
  12.   p.Orientation := poPortrait;
  13.   p.PageSize.PaperName := 'A4';
  14.   p.Data := lReportData;
  15. ....
  16.   Memo := TFPReportMemo.Create(DataBand);
  17.   Memo.Font.Name := defaultFont;
  18.   Memo.Text := 'Hello world <[userdata.string]>.';
  19. ....
  20. procedure TFrmSimpleReportLCL.GetReportDataFirst(Sender: TObject);
  21. begin
  22.   // Nothing to do yet, but needed
  23. end;
  24.  
  25. procedure TFrmSimpleReportLCL.GetReportDataValue(Sender: TObject;
  26.   const AValueName: String; var AValue: Variant);
  27. begin
  28.   if (AValueName = 'element') or (AValueName = 'string') then
  29.   begin
  30.     AValue := sl[lReportData.RecNo-1];
  31.   end
  32.   else
  33.     AValue:=AValueName+IntToStr(lReportData.RecNo);
  34. end;
  35.  
  36. procedure TFrmSimpleReportLCL.GetReportDataEOF(Sender: TObject;
  37.   var IsEOF: Boolean);
  38. begin
  39.   if lReportData.RecNo > sl.Count then
  40.     IsEOF := True
  41.   else
  42.     IsEOF := False;
  43. end;
  44.  
  45. procedure TFrmSimpleReportLCL.GetReportDataNames(Sender: TObject;
  46.   List: TStrings);
  47. begin
  48.   List.Add('element');
  49.   List.Add('string');
  50.   List.Add('FirstName');
  51.   List.Add('LastName');
  52.   List.Add('DateOfBirth');
  53.   List.Add('Gender');
  54.   List.Add('Email');
  55. end;
  56.  
  57. procedure TFrmSimpleReportLCL.InitialiseData;
  58. var
  59.   i: integer;
  60. begin
  61.   sl := TStringList.Create;
  62.   for i := 1 to 50 do
  63.     sl.Add(Format('Item %d', [i]));
  64. end;
  65. ....
  66.  

This code was working some time ago, but something is changed in the expressionparser, now i got the errormessage .... EExprParser ... 'Unknown identifier: userdata.string

The full code is in lazarus trunk examples\fpreport\simple\SimpleReportLCL.lpr.

I have looked in the wiki of fpreport, but the TFPReportUserData have not explained. Any hint what is changed/going wrong now?

Andreas
 
regards
Andreas

MvC

  • New member
  • *
  • Posts: 10
Re: fpreport: TFPReportUserData work not as expected
« Reply #1 on: April 26, 2018, 11:59:35 am »
This should still work.

If for some reason it does not, please post a sample program to demonstrate the issue in the FPC bugtracker.

af0815

  • Jr. Member
  • **
  • Posts: 68
Re: fpreport: TFPReportUserData work not as expected
« Reply #2 on: April 26, 2018, 08:52:56 pm »
Bug ID 33656 https://bugs.freepascal.org/view.php?id=33656

The sample code is in lazarus\examples\fpreport\simple\SimpleReportLCL.lpr
regards
Andreas

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus