Load report in Windows Service

edited March 2013 in FastReport 4.0
I want to generate a PDF file in the Windows Service. I use Delphi XE2 with FastRepor 4.12.2.

On the line where loaded from the database, the service is completely stops. After uninstall service generates a blank PDF.
LoadFromBlobField(frxReport, QuerySestava.FieldByName('obsah'));
procedure TSAODV.LoadFromBlobField(frxReport: TfrxReport; Blob: TField);
var Stream: TMemoryStream;
begin
  Stream := TMemoryStream.Create;
  try
    TBlobField(Blob).SaveToStream(Stream);
    Stream.Position := 0;
    frxReport.LoadFromStream(Stream);
  finally
    Stream.Free;
  end;
end;
I tried the code below does not work.
frxReport.LoadFromStream(QuerySestava.CreateBlobStream(TBlobField(QuerySestava.FieldByName('obsah')),bmRead));
The above lines in the standard program are OK.

Thanks for the advice.

Comments

  • gpigpi
    edited 10:15AM
    try to save report to file after frxReport.LoadFromStream(Stream); and check content of report template
  • edited April 2013
    I forgot to set up the connection to the database for the report.
    ADOComp := TfrxADOComponents.Create(Self);
    ADOComp.DefaultDatabase := ADOConnection;
    frxReport := TfrxReport.Create(Self);
    frxReport.Script.Parent := fsGlobalUnit;
    frxReport.LoadFromStream(QuerySestava.CreateBlobStream(TBlobField(QuerySestava.FieldByName('obsah')),bmRead));
    
    Thanks, it all works OK.
  • edited April 2013
    zkusmo wrote: »
    frxReport.LoadFromStream(QuerySestava.CreateBlobStream(TBlobField(QuerySestava.FieldByName('obsah')),bmRead));
    
    Thanks, it all works OK.

    Hello,

    Almost OK.
    CreateBlobStream() returns a stream that you need to free. Especially if, I assume, this is a server.
    strm := QuerySestava.CreateBlobStream(TBlobField(QuerySestava.FieldByName('obsah')),bmRead);
    try
      frxReport.LoadFromStream(strm);
    finally
      strm.Free;
    end;
    

    Best Regards,
    Cristian Peta

Leave a Comment