![]() |
Intraweb and fast report - Printable Version +- Atozed Forums (https://www.atozed.com/forums) +-- Forum: Atozed Software Products (https://www.atozed.com/forums/forum-1.html) +--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html) +---- Forum: English (https://www.atozed.com/forums/forum-16.html) +----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html) +----- Thread: Intraweb and fast report (/thread-2191.html) |
Intraweb and fast report - softdev85 - 12-16-2020 hello, I am dummy with fastreport i never use. I have build software with intraweb that use mysql database, he work well. Ido some sql query, and the result are writen on screen, but i want now build report with the result of this query in pdf and i want also print them. Have you just a small example for understand how work with fast report, in intraweb software ? thank's a lot for your help Best regards RE: Intraweb and fast report - softdev85 - 12-16-2020 hello, i have understood for build query and report is ok now, i have just a little problem now, my preview page are not on top or modal, have you any ideas for have my page preview visible on top thank's a lot best regards RE: Intraweb and fast report - zsleo - 12-16-2020 (12-16-2020, 09:04 PM)softdev85 Wrote: hello, Because of Fast Reports threading issues, my Fast Report processes and report generation is in a DLL. If I started the development again I would use the IW CGI Runner utility https://github.com/Atozed/IntraWeb/tree/master/15/Delphi/CGIRunner/CGIRunner2 This a much better solution. There are some Fast Report / IW setting that are supposed to cater for Fast Report threading. IMHO, I would NOT embed Fast Report components into my master IW application. Hope this helps. RE: Intraweb and fast report - joel - 12-18-2020 function TrDMRepTOR.fxProcess_Report(aProgramSwitch: string; aDataModule: TDataModule; aDatasetLst: TObjectList; aReportObjID: string; aRunDate: TDateTime; aExportFileExtType: string; aRenderType: EN_RenderType; aRptParamList: DataParameterArray; var aPdfStream: TROBinaryMemoryStream; aFileName: string = ''; aPdfPassword: string = ''; aShareName: string = ''): boolean; var lAvailDS: TEdDataSets; lAvailQrys: TEdDataQueries; lAvailDBCxn: TEdDatabase; lFrxReport: TfrxReport; lTempFileName: AnsiString; lURL: string; {$IFDEF IS_WIN32} lErrorCode: integer; {$ENDIF} {$IFDEF USE_GNOSTICE} lgtFRExportIntf: TgtFRExportInterface; lgtPDFEngine: TgtPDFEngine; {$ELSE} lFrxPDFExport: TfrxPDFExport; {$ENDIF} lRptVars: U_ReportVars; lVer, lTitle : string; lReportID: string; lReportOrigin: EN_ReportOrigin; lReportType: EN_ReportType; lUAAdhocSQL: UA_AdhocQryParam; lTemplateID: string; procedure fxProcessAsRptDB; begin fxRetrieveAdhoc(lReportID, aRptParamList, lUAAdhocSQL); fxLoadDBReport(lReportID, lFrxReport, lRptVars); lFrxReport.CheckDataPage; // BIND DBCXN TO REPORT lAvailDBCxn := TEdDatabase.Create(lFrxReport, 'DBCxn'); lAvailQrys := TEdDataQueries.Create; fxRetrieveDBCxnInfo(lReportID, lAvailDBCxn); // SET PARAMS PER IS_RUNTIME FLAG // fxRetrieveRunTimeParams( lUAAdhocSQL ); // SET QRY lAvailQrys.fxPopulateWithAdhocSQL(lFrxReport, lAvailDBCxn, lUAAdhocSQL); lAvailQrys.fxRegisterWithReport(lFrxReport); lAvailQrys.fxActivateNeededQueries(lFrxReport, False, lUAAdhocSQL, aRptParamList); end; procedure fxProcessAsRptFile; begin lAvailDS := TEdDataSets.Create; // Make sure that this is set to false so that the frxdb data sources will not be freed; otherwise on the 2nd pass // the prepare report will fail. aDatasetLst.OwnsObjects := False; lAvailDS.fxPopulateWithTDataset(aDataModule, aDatasetLst); lAvailDS.fxRegisterWithReport(lFrxReport); // Loading the report afterward because in this case the report has the definition and the data is in the datamodule. fxLoadFileReport(lReportID, lFrxReport, lVer, lTitle); lAvailDS.fxActivateNeededDatasets(lFrxReport, True); end; begin Result := False; // WE SET lAvailDS = NIL.. because for some reason it appears as being assigned. NO IDEA WHY lAvailDS := nil; // Trap for some unforescene error try // SET SOURCE OF REPORT (IE FILE OR DB) if ((aDataModule <> nil) and (aDatasetLst.Count <> 0)) then begin lReportOrigin := roFile; lReportID := aReportObjID; end else begin lReportOrigin := roDB; //get the information that is needed to process the report // lReportID := fxRetrieveReportID(aReportObjID, aRunDate, lReportType); lReportID := fxRetrieveReportID(aReportObjID, aRunDate); end; lUAAdhocSQL := UA_AdhocQryParam.Create(nil); lRptVars := U_ReportVars.Create(nil); lFrxReport := TfrxReport.Create(nil); try // this code is very important and needs to be called right after the report is created. lFrxReport.EngineOptions.EnableThreadSafe := True; lFrxReport.EngineOptions.UseGlobalDataSetList := False; lFrxReport.ReportOptions.Compressed := True; lFrxReport.EngineOptions.SilentMode := True; //https://www.youtube.com/watch?v=PUUQ7LUbhD4 lFrxReport.EngineOptions.DestroyForms := True; lFrxReport.EngineOptions.UseFileCache := False; lFrxReport.ShowProgress := False; lFrxReport.OnLoadTemplate := frxReportLoadTemplate; lTemplateID := fxLoadTemplate(aReportObjID); if lTemplateID <> '' then begin lFrxReport.InheritFromTemplate(lTemplateID, imRename); end; if lReportOrigin = roDB then begin fxProcessAsRptDB end else begin fxProcessAsRptFile; end; if lTemplateID <> '' then frxReportLoadTemplateScript(lFrxReport, lTemplateID); // BIND PARAMS {$IFDEF IS_MT} lRptVars.zVarLogoPath := HDM.gLogoPath; {$ELSE} lRptVars.zVarLogoPath := Controller.gLogoPath; // IW and WinApp {$ENDIF} fxAssignParams(lFrxReport, lRptVars, aRptParamList); // CURRENTLY NO OTHER EXPORT TYPES OTHER THAN PDF BUT COULD DO XLS, ETC {$REGION 'EXPORT AS PDF'} if (UPPERCASE(aExportFileExtType) = 'PDF') then begin {$IFDEF USE_GNOSTICE} lgtFRExportIntf := TgtFRExportInterface.Create(nil); lgtPDFEngine := TgtPDFEngine.Create(nil); {$ELSE} lFrxPDFExport := TfrxPDFExport.Create(nil); {$ENDIF} try if aFileName = '' then lTempFileName := fxGetSmallGUID else // GENERATE UNIQUE FILE_NAME lTempFileName := aFileName + '_' + uAppCommon.fxGetFileSafeDT(NOW); if aShareName <> '' then lTempFileName := aShareName + lTempFileName; lTempFileName := lTempFileName + '.' + aExportFileExtType; {$IFDEF USE_GNOSTICE} lgtPDFEngine.Font.Name := 'Garamond'; lgtPDFEngine.Font.Size := 12; lgtPDFEngine.FontEmbedExcludeList.Add('Arial'); lgtPDFEngine.Preferences.EmbedTrueTypeFonts := etfNone; // etfSubset; // etfFull; etfSubset etfNone; { TO IMPLEMENT LATER if aPdfPassword <> '' then begin lgtPDFEngine.Encryption.Level := el128Bit; lgtPDFEngine.Encryption.Enabled := True; lgtPDFEngine.Encryption.OwnerPassword := aPdfPassword + '_owner'; lgtPDFEngine.Encryption.UserPassword := aPdfPassword + '_user'; end; } lgtFRExportIntf.Engine := lgtPDFEngine; lgtPDFEngine.Preferences.OutputToUserStream := True; IgtDocumentEngine(lgtFRExportIntf.Engine).FileName := ''; lgtPDFEngine.UserStream := aPdfStream as TMemoryStream; IgtDocumentEngine(lgtFRExportIntf.Engine).Preferences.ShowSetupDialog := False; IgtDocumentEngine(lgtFRExportIntf.Engine).Preferences.OpenAfterCreate := False; IgtDocumentEngine(lgtFRExportIntf.Engine).Preferences.ProcessAfterEachPage := False; lgtFRExportIntf.ShowSaveDialog := False; {$ELSE} lFrxPDFExport.Stream := aPdfStream as TMemoryStream; lFrxPDFExport.DefaultExt := aExportFileExtType; lFrxPDFExport.HideWindowUI := True; lFrxPDFExport.OpenAfterExport := False; lFrxPDFExport.ShowDialog := False; lFrxPDFExport.ShowProgress := False; lFrxPDFExport.UseFileCache := False; lFrxPDFExport.Compressed := True; lFrxPDFExport.CenterWindow := False; lFrxPDFExport.FitWindow := True; {$ENDIF} try if lFrxReport.PrepareReport(True) then begin {$IFDEF IS_IW} begin {$IFDEF USE_GNOSTICE} lgtFRExportIntf.RenderDocument(lFrxReport, False, False); {$ELSE} lFrxReport.Export(lFrxPDFExport); {$ENDIF} aPdfStream.Position := 0; lURL := TIWAppCache.StreamToCacheFile(WebApplication, aPdfStream, CGGetContentTypeForExtension(aExportFileExtType), ctSession); fxRenderStaticDoc(lURL , aRenderType , lTempFileName ); end; {$ENDIF} {$IFDEF IS_WIN32} begin lErrorCode := 0; {$IFDEF USE_GNOSTICE} lgtFRExportIntf.RenderDocument(lFrxReport, False, False); {$ELSE} lFrxReport.Export(lFrxPDFExport); {$ENDIF} aPdfStream.Position := 0; aPdfStream.SaveToFile(lTempFileName); end; {$ENDIF} {$IFDEF IS_MT} begin {$IFDEF USE_GNOSTICE} if aShareName <> '' then begin lgtFRExportIntf.RenderDocument(lFrxReport, False, False); aPdfStream.Position := 0; aPdfStream.SaveToFile(lTempFileName); end else begin lgtFRExportIntf.RenderDocument(lFrxReport, False, False); end; {$ELSE} if aShareName <> '' then begin lFrxReport.Export(lFrxPDFExport); aPdfStream.Position := 0; aPdfStream.SaveToFile(lTempFileName); end else begin lFrxReport.Export(lFrxPDFExport) end; {$ENDIF} end; {$ENDIF} // WE'VE GOT THIS FAR, SO WE MUST ASSUME ALL IS WELL Result := True; end else begin // PREPARE REPORT FAILED, SO WE MUST ASSUME THE REPORT RENDERING FAILED Result := False; raise Exception.Create(lFrxReport.Errors.Text); end; except Result := False; raise; end; finally {$IFDEF USE_GNOSTICE} FreeAndNil(lgtFRExportIntf); FreeAndNil(lgtPDFEngine); {$ELSE} FreeAndNil(lFrxPDFExport); {$ENDIF} end; end // Export PDF {$ENDREGION} else begin if lFrxReport.PrepareReport then lFrxReport.ShowPreparedReport else raise Exception.Create(lFrxReport.Errors.Text); end; // WE SET lAvailDS = NIL EARLY BECAUSE FOR SOME UNKNOWN REASON IT WAS APPEARING AS // BEING ASSIGNED WHEN IT SHOULD NOT BE if Assigned(lAvailDS) then begin lAvailDS.fxResetDataSetBookMark(lFrxReport); FreeAndNil(lAvailDS); end; finally // DO NOT FREE lUAAdhoSQL (RO HANDLES THIS INTERNALLY) {$IFDEF IS_IW} FreeAndNil(lUAAdhocSQL);; {$ENDIF} lFrxReport.Free; lRptVars.Free; end; except on E: Exception do raise Exception.Create('ERROR: Failed to Prepare Report. ' + E.Message); end; end; |