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 1:13AM
    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

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.