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;