Can't prepare report in a W32 Service
FAlvarado
US/Mexico
I'm developing a Service application using DXE5, ADOQueries and Fast-Reports 4 Pro to generate a graph and export it to PDF file to be displayed in a WEB application. A second thread is called from within the service main thread.
The problem I'm experimenting is that the report is not prepared and it's closed! The resulting PDF file is empty, no graph and no bands
see bellow: ****** Error Can't prepare report *********
If I run the resulting query and prepare a report in an desktop application it runs Ok.
Any idea of what I'm doing wrong?
Best Regards
Francisco Alvarado
The report thread
The problem I'm experimenting is that the report is not prepared and it's closed! The resulting PDF file is empty, no graph and no bands
see bellow: ****** Error Can't prepare report *********
If I run the resulting query and prepare a report in an desktop application it runs Ok.
Any idea of what I'm doing wrong?
Best Regards
Francisco Alvarado
The report thread
uses
WinApi.Windows, WinApi.Messages, System.SysUtils, System.Classes,
frxChart, frxOLE, frxClass, frxExportHTML, ComObj, frxExportPDF, frxDBSet, Data.DB, Data.Win.ADODB, WinApi.ActiveX;
// in the execute procedure:
if Assigned(ComObj.CoInitializeEx) then
CoInitializeEx(nil, COINIT_MULTITHREADED)
else
CoInitialize(nil);
// Do NOT free on termination - The Service frees the Thread
FreeOnTerminate := False;
// Create Components
ADOConnection1 := TADOConnection.Create(nil);
ADOConnection1.Connected := False;
ADOConnection1.ConnectionString := Connection;
ADOQuery1 := TADOQuery.Create(nil);
frxReport1 := TfrxReport.Create(nil);
frxReport1.EngineOptions.SilentMode := True;
frxReport1.EngineOptions.EnableThreadSafe := True;
frxReport1.EngineOptions.UseFileCache := false;
frxReport1.ShowProgress := False;
frxReport1.Engine.OnRunDialog := ShowReportDialog;
frxChartObject1 := TfrxChartObject.Create(nil);
frxDBDataset1 := TfrxDBDataset.Create(nil);
// create PDF export object for test
frxPDFExport1 := TfrxPDFExport.Create(nil);
frxPDFExport1.ShowDialog := False;
frxPDFExport1.ShowProgress := False;
// Create HTML export object
frxHTMLExport1 := TfrxHTMLExport.Create(nil);
frxHTMLExport1.ShowDialog := False;
frxHTMLExport1.ShowProgress := False;
// Set components properties
ADOConnection1.ConnectionString := Connection;
ADOConnection1.LoginPrompt := False;
ADOQuery1.Connection := ADOConnection1;
ADOConnection1.Connected := True;
// Prepare the query
ADOQuery1.Close;
ADOQuery1.Prepared := False;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('SELECT * FROM RepTable');
ADOQuery1.Prepared := True;
ADOQuery1.Open;
WriteLog('Srvc.log', IntToStr(ADOQuery1.RecordCount) + ' Records' +#13+ ADOQuery1.SQL.Text);
// The SQL is fine, it runs Ok and there are 7 rows in result; the query is NOT empty
if not ADOQuery1.Eof then
begin
if frxReport1.LoadFromFile('C:\Reports\ReportTest.fr3') then // Report loads Ok
begin
frxDBDataset1.DataSet := ADOQuery1;
frxReport1.DataSet := frxDBDataset1; // just in case
frxPDFExport1.FileName := 'Report.pdf';
try
if frxReport1.PrepareReport(True) then // or frxReport1.PrepareReport(false) same behaviour
begin
if frxReport1.Export(frxPDFExport1) then
// Ok
else
WriteLog('Srvc.log', 'Error Exporting Report');
end
else
WriteLog('Srvc.log', 'Error Preparing Report'); // ****** Error Can't prepare report *********
except
on E: Exception do
WriteLog('Srvc.log', 'Error preparing' + frxReport1.ReportOptions.Name + ' for ' + Name +#13+ E.Message);
// NO Exception here
end;
WriteLog('Srvc.log', frxReport1.ReportOptions.Name); // the name of the report is blank
frxReport1.Clear;
end
else
WriteLog('Srvc.log', 'Can''t load report ' + 'ReportTest.fr3');
end;
Comments
Works perfectly on a Win 2003 Server and Win 7.
TIA
Okay! [img]style_emoticons/<#EMO_DIR#>/rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:" border="0" alt="rolleyes.gif" /> My application works as expected... Still don't have an answer to my problem...[/img]
I still can't get it working. ..
Anyone from FRIDAY watching this forum?