* * *

Author Topic: fpReport, am I using it wrong?  (Read 2313 times)

mobilevil

  • New member
  • *
  • Posts: 45
    • http://www.kachun.com
fpReport, am I using it wrong?
« on: September 25, 2017, 05:15:22 pm »
Hello,
I am not sure if I am using it wrong, or the Lazarus part of fpReport is too alpha to use...

The fpReport demo in FPC works, and I am trying to have fpReport working from lazarus. So the first thing to do is to try the design project under Lazarus\components\fpreport\design.

it compile and run fine. I can create data connections, sqldb, firebird or dbf. (there is no confirmation for a successful connection?)
but I can't assign the data to the report or databand. it keeps getting back to blank.

Next I tried to copy the sample FPC source to Lazarus, and replace the dynamically created objects with form components. It creates the PDF fine until I replace lReportData with a form created TFPReportDatasetData. The application crashes with exception class EExprParser with message: Unknown identifier:name


procedure TForm1.Button2Click(Sender: TObject);
var
  lReportData: TFPReportDatasetData;
  p: TFPReportPage;
  TitleBand: TFPReportTitleBand;
  Memo: TFPReportMemo;
  DataBand: TFPReportDataBand;
  Image: TFPReportImage;

begin

  if not FileExists(cFCLReportDemosLocation + '\' + 'test.dbf') then
  begin
    writeln('Unable to find database file <' + cFCLReportDemosLocation + 'test.dbf>');
    writeln('Please run the fcl-report''s dataset demo at least once.');
    writeln('');
    exit;
  end;

  // ***** Creating the report *****
  PaperManager.RegisterStandardSizes;

  rpt.Author := 'Graeme Geldenhuys';
  rpt.Title := 'FPReport Demo 8 - Datasets';
  try
    // ***** Providing data to the report, dynamic *****
    //lReportData := TFPReportDatasetData.Create(nil);
    //lReportData.DataSet := Dbf1;


    // ***** Providing data to the report, form component *****
    rpt.ReportData.AddReportData(FPReportDatasetData1);
    FPReportDatasetData1.DataSet:=dbf1;



    // ***** Adding a page *****
    p := TFPReportPage.Create(rpt);
    p.Orientation := poPortrait;
    p.PageSize.PaperName := 'A4';

    { page margins }
    p.Margins.Left := 30;
    p.Margins.Top := 20;
    p.Margins.Right := 30;
    p.Margins.Bottom := 20;

    { page's default font }
    p.Font.Name := 'LiberationSans';  // this is the PostScript name of the TTF font

    { assign the data for the page data loop }
    //dynamic
    //p.Data := lReportData;  //this is ok
    //p.Data := rpt.ReportData.Data[0].Data; //this doesn't work...

    //form component
    p.Data :=  FPReportDatasetData1;

    // ***** Adding bands to a page *****
    TitleBand := TFPReportTitleBand.Create(p);
    TitleBand.Layout.Height := 40;

    Memo := TFPReportMemo.Create(TitleBand);
    Memo.Layout.Left := 5;
    Memo.Layout.Top := 0;
    Memo.Layout.Width := 140;
    Memo.Layout.Height := 15;

    Memo.Text := 'GUI Dataset Demo';

    Memo.TextAlignment.Vertical := TFPReportVertTextAlignment.tlCenter;
    Memo.TextAlignment.Horizontal := taCentered;

    Memo.UseParentFont := False;
    Memo.Font.Color := TFPReportColor($000080);
    Memo.Font.Size := 24;

    // ***** The loop data *****
    DataBand := TFPReportDataBand.Create(p);
    DataBand.Layout.Height := 30;

    //dynamic
    //DataBand.Data:= lReportData;
    //form created
    p.Data :=  FPReportDatasetData1;

    Memo := TFPReportMemo.Create(DataBand);
    Memo.Layout.Left := 30;
    Memo.Layout.Top := 0;
    Memo.Layout.Width := 50;
    Memo.Layout.Height := 5;
    Memo.Text := 'Name: [name]';

    // ***** Image Support *****
    Image := TFPReportImage.Create(DataBand);
    Image.Layout.Top := 0;
    Image.Layout.Left := 10;
    Image.Layout.Height := 20;
    Image.Layout.Width := 14.8;
    Image.FieldName := 'Photo';
    Image.Stretched := True;

    Image := TFPReportImage.Create(TitleBand); // note this one is placed on the TitleBand
    Image.Layout.Left := 0;
    Image.Layout.Top := 0;
    Image.Layout.Width := 40;
    Image.Layout.Height := 30;
    Image.LoadFromFile(cFCLReportDemosLocation + '\pictures\woman01.png');
    Image.Stretched := True;

    // ***** Running the report *****
    { specify what directories should be used to find TrueType fonts }
    gTTFontCache.SearchPath.Add(cFCLReportDemosLocation + '\fonts\');
    gTTFontCache.BuildFontCache;

    rpt.RunReport;

    // ***** Rendering (or exporting) the report *****
    rpt.RenderReport(FPReportExportPDF1);

  finally
    // Freeing all objects we used

  end;

end;         

eldonfsr

  • Full Member
  • ***
  • Posts: 118
Re: fpReport, am I using it wrong?
« Reply #1 on: October 08, 2017, 08:39:12 pm »
How you get compile I tried but when put the fpreport to compile component send invalid unti name but i dont put send need that unit to compile can explain more how you get to compile pls.

mobilevil

  • New member
  • *
  • Posts: 45
    • http://www.kachun.com
Re: fpReport, am I using it wrong?
« Reply #2 on: October 09, 2017, 04:26:14 am »
Hi,
FPReport is only available in trunk as of now, and it is only enabled under Windows 32bit build.
I use FPCUpdateDeluxe to get my copy.

https://github.com/newpascal/fpcupdeluxe

Pascal

  • Hero Member
  • *****
  • Posts: 664
Re: fpReport, am I using it wrong?
« Reply #3 on: October 09, 2017, 08:08:21 am »
Try to add:
Code: Pascal  [Select]
  1.  FPReportDatasetData1.InitFieldDefs;
after
Code: Pascal  [Select]
  1. // ***** Providing data to the report, form component *****
  2. rpt.ReportData.AddReportData(FPReportDatasetData1);
  3. FPReportDatasetData1.DataSet:=dbf1;

The error message means that the field "name" is not in the dataset.

Pascal
« Last Edit: October 09, 2017, 08:10:39 am by Pascal »
laz trunk - fpc trunk 32bit - Windows 10 Pro x64 (1803)

mobilevil

  • New member
  • *
  • Posts: 45
    • http://www.kachun.com
Re: fpReport, am I using it wrong?
« Reply #4 on: October 09, 2017, 10:09:02 am »
Thanks for the suggestion but adding the InitFieldDefs call doesn't fix the issue for me :( and it couldn't explain why the design project is not able to use data set created within the designer UI.
not sure if I have time to look into the fpreport source code to see what's wrong.

Try to add:
Code: Pascal  [Select]
  1.  FPReportDatasetData1.InitFieldDefs;
after
Code: Pascal  [Select]
  1. // ***** Providing data to the report, form component *****
  2. rpt.ReportData.AddReportData(FPReportDatasetData1);
  3. FPReportDatasetData1.DataSet:=dbf1;

The error message means that the field "name" is not in the dataset.

Pascal

 

Recent

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