Recent

Author Topic: FPReport: Data in Base64?  (Read 1641 times)

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1315
FPReport: Data in Base64?
« on: January 26, 2023, 03:23:59 pm »
If I make this table:

Code: [Select]
create table TestTable (ID integer, Description text, Comment text);
insert into TestTable (ID, Description, Comment) values (1, "Zomg", "Bla");

and run this code:

Code: Pascal  [Select][+][-]
  1. procedure TMainForm.ReportButtonClick(Sender: TObject);
  2. var
  3.   q: TSQLQuery;
  4.   rpt: TFPReport;
  5.   dat: TFPReportDatasetData;
  6.   p: TFPReportPage;
  7.   memo: TFPReportMemo;
  8.   title: TFPReportTitleBand;
  9.   data: TFPReportDataBand;
  10.   exporter: TFPReportExportPDF;
  11. begin
  12.   PaperManager.RegisterStandardSizes;
  13.   rpt := TFPReport.Create(nil);
  14.   rpt.Author := 'Frank';
  15.   rpt.Title := 'Test';
  16.  
  17.   q := TSQLQuery.Create(nil);
  18.   q.SQLConnection := LiteConnection;
  19.   q.SQL.Text := 'select * from TestTable';
  20.   q.Open;
  21.   dat := TFPReportDatasetData.Create(nil);
  22.   dat.DataSet := q;
  23.   p := TFPReportPage.Create(rpt);
  24.   p.Orientation := poPortrait;
  25.   p.PageSize.PaperName := 'A4';
  26.   p.Margins.Left := 30;
  27.   p.Margins.Top := 20;
  28.   p.Margins.Right := 30;
  29.   p.Margins.Bottom := 20;
  30.   p.Font.Name := 'LiberationSans';
  31.   p.Data := dat;
  32.   title := TFPReportTitleBand.Create(p);
  33.   title.Layout.Height := 40;
  34.   memo := TFPReportMemo.Create(title);
  35.   memo.Layout.Left := 5;
  36.   memo.Layout.Top := 0;
  37.   memo.Layout.Width := 140;
  38.   memo.Layout.Height := 15;
  39.   memo.Text := rpt.Title;
  40.   memo.TextAlignment.Vertical := tlCenter;
  41.   memo.TextAlignment.Horizontal := taCentered;
  42.   memo.UseParentFont := False;
  43.   memo.Font.Color := TFPReportColor($000080);
  44.   memo.Font.Size := 24;
  45.   data := TFPReportDataBand.Create(p);
  46.   data.Layout.Height := 30;
  47.   data.Data:= dat;
  48.   memo := TFPReportMemo.Create(data);
  49.   memo.Layout.Left := 30;
  50.   memo.Layout.Top := 0;
  51.   memo.Layout.Width := 150;
  52.   memo.Layout.Height := 50;
  53.   memo.Text := 'ID: [ID], Description: [Description], Comment: [Comment]';
  54.  
  55.   gTTFontCache.SearchPath.Add('.\fonts\');
  56.   gTTFontCache.BuildFontCache;
  57.   rpt.RunReport;
  58.   exporter := TFPReportExportPDF.Create(nil);
  59.   rpt.RenderReport(exporter);
  60.  
  61.   exporter.Free;
  62.   dat.Free;
  63.   rpt.Free;
  64.   q.Free;
  65. end;
  66.  

Then this is what is printed on the report:

Code: [Select]
ID: 1, Description: Wm9tZw==, Comment: Qmxh
???

It looks like Base64.

I did try multiple different versions of freetype-6.ddl, as from the FAQ, but that doesn't make a difference. This is with fpc/Lazarus checked out at 2023-01-02, on Windows 10 64bit.

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1315
Re: FPReport: Data in Base64?
« Reply #1 on: January 30, 2023, 09:11:14 am »
Well, I have been debugging this a bit, but it's not easy to understand. So, unless someone knows what is happening, I think LazReport is a better choice.

eldonfsr

  • Sr. Member
  • ****
  • Posts: 458
Re: FPReport: Data in Base64?
« Reply #2 on: February 01, 2023, 02:28:50 am »
Wow i try some similar but i don't get work , I using lazreport, because fpreport documentation is poor and also who support  fperpot......

Thaddy

  • Hero Member
  • *****
  • Posts: 15139
  • Censorship about opinions does not belong here.
Re: FPReport: Data in Base64?
« Reply #3 on: February 01, 2023, 08:54:18 am »
Well, I have been debugging this a bit, but it's not easy to understand. So, unless someone knows what is happening, I think LazReport is a better choice.
I think not. fpreport is relatively new, much better structured and much easier to use. The two main authors are part of the core developer team. It is likely that you simply miss the set of controls that lazreport has. I strongly advise you use fpreport.
Of course the national anthem of the U.S.A. was written by Jimi Hendrix, didn't you know that?

af0815

  • Hero Member
  • *****
  • Posts: 1334
Re: FPReport: Data in Base64?
« Reply #4 on: February 01, 2023, 09:45:17 am »
There is a sample in Lazarus as a starting point for fpreport. And in Lazarus is a builder for fpreport and with this you can also test reports.

fpreport have some issue if you have to use more datasets (no Master-Detail) for complex reports, there is LazReport more flexible. ANd the core developer says "it is by design" to handle only one dataloop, no changes planned yet.

Edit: I have here https://github.com/afriess/fpReportSamples/tree/master/source some samples and in the branch wip_tests is a try for a converter Reports To Pascal Source. (It was a idea to make a report with the designer and later sourcecode from this report)
« Last Edit: February 01, 2023, 09:55:06 am by af0815 »
regards
Andreas

paweld

  • Hero Member
  • *****
  • Posts: 1087
Re: FPReport: Data in Base64?
« Reply #5 on: February 01, 2023, 01:01:35 pm »
This is because the sql data type text is mapped to ftMemo, which FPReports considers a Stream and converts to Base64. You can get around this by creating a custom dataset that changes the ftMemo type to String.Sample in attachment
Best regards / Pozdrawiam
paweld

af0815

  • Hero Member
  • *****
  • Posts: 1334
Re: FPReport: Data in Base64?
« Reply #6 on: February 01, 2023, 01:14:04 pm »
Thx for the sample. Interesting.
regards
Andreas

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1315
Re: FPReport: Data in Base64?
« Reply #7 on: February 01, 2023, 09:03:17 pm »
This is because the sql data type text is mapped to ftMemo, which FPReports considers a Stream and converts to Base64. You can get around this by creating a custom dataset that changes the ftMemo type to String.Sample in attachment

Thanks. But my code is almost exactly the example from the wiki. You have to start somewhere with working code.

af0815

  • Hero Member
  • *****
  • Posts: 1334
Re: FPReport: Data in Base64?
« Reply #8 on: February 01, 2023, 09:20:54 pm »
It depends, how a coloumn is defined and what kind of DB is used. You can try the demo in fpc sources direct (src/packages/fcl-report/demos/), if this demo have the same issue you can file a bug.
regards
Andreas

paweld

  • Hero Member
  • *****
  • Posts: 1087
Re: FPReport: Data in Base64?
« Reply #9 on: February 02, 2023, 06:44:05 am »
@SymbolicFrank:
if you declare the table structure as:
Code: SQL  [Select][+][-]
  1. CREATE TABLE TestTable (ID INTEGER, Description VARCHAR(4000), Comment VARCHAR(4000));  
  2.  
  3. /* set data type `varchar(4000)` instead of `text`*/
or you leave the current table structurę but change the query getting data to report to:
Code: SQL  [Select][+][-]
  1. SELECT ID, CAST(Description AS VARCHAR(4000)) Description, CAST(Comment AS VARCHAR(4000)) Comment FROM TestTable;  
  2.  
  3. /*instead of: `select * from TestTable`*/


then your report generating code will work without any changes, and the text will be normally visible on the report and not encoded to base64.
Best regards / Pozdrawiam
paweld

 

TinyPortal © 2005-2018