Marco1979 Posted September 17, 2021 Share Posted September 17, 2021 Hi everyone, I don't write much in this forum but I follow all the problems that are exposed and you have often solved me many problems about creating code with unigui objects. I wanted to ask you a question about a problem that I just can't solve: I use Fast Report to create reports. I set all the parameters correctly (so it seems to me), even taking inspiration from the Demo projects and from the advice of other users. Only that the first time the report is loaded, it shows a blank page, just the page with the report header, with no data. If I reload the report again, the data also comes out and the report is displayed correctly. Below is the procedure created to generate the report: procedure TMDL_REPORT.CaricaReport(ID,Modalita:Integer;var FileReport:String;ParametriFissi:String;FixedFileName,FixedFilePath:String); var I,contImg:Integer; FileName,nameImg:String; appoPicture:TfrxPictureView; begin CloseDS; //Carico il report dalla tabella LoadDati(ID); report.Destroy; report:=TfrxReport.Create(Self); report.EngineOptions.SilentMode := True; report.EngineOptions.EnableThreadSafe := True; report.EngineOptions.DestroyForms := False; report.PrintOptions.ShowDialog := False; report.ShowProgress:=false; report.LoadFromFile(SRV_MAIN.StartPath+'images\report\' + rsREPORTREP_CODICE.AsString + '.fr3'); //Caricamento parametri di avvio report if (rsPARVISPAR_VISIBLE.AsString='1') then if DGL_REPORT_PARAMETER.GetParametri(rsPARAMETER,rsREPORTREP_NOME.AsString,ID)=False then Exit; try //Esecuzione STORED LoadStoredReport(ParametriFissi); report.EnabledDataSets.Clear; //Caricamento dataset CaricaDataset; AssignLinkFields; //Inizializzo i valori delle variabili if (report.Variables.Count>0) and (rsPARAMETER.RecordCount>0) then begin for I:=0 to report.Variables.Count-1 do begin //Ricerco nella tabella rsPARAMETER.First; while not rsPARAMETER.Eof do begin if rsPARAMETERPAR_NOME.Value=report.Variables.Items[I].Name then begin //Assegno il valore if (rsPARAMETERPAR_NASCOSTO.Value) and (rsPARAMETERPAR_DISPLAYDEF.AsString<>'') then report.Variables.Items[I].Value:='''' + rsPARAMETERPAR_DISPLAYDEF.AsString + '''' else if (rsPARAMETERPAR_NASCOSTO.Value=False) and (rsPARAMETERPAR_VALORE.AsString<>'') then report.Variables.Items[I].Value:='''' + rsPARAMETERPAR_VALORE.AsString + ''''; end; rsPARAMETER.Next; end; end; end; //caricamento immagini loghi for contImg := 0 to report.ComponentCount-1 do begin if report.Components[contImg] is TfrxPictureView then begin nameImg:=TfrxPictureView(report.Components[contImg]).Name; //ricerco nella cartella immagine se è presente il file con questo nome if FileExists(SRV_MAIN.StartPath+'images\report\'+nameImg+'.png') then begin AppoPicture:=report.FindObject(nameImg) as TfrxPictureView; if appoPicture<>nil then appoPicture.Picture.LoadFromFile(SRV_MAIN.StartPath+'images\report\'+nameImg+'.png'); end; appoPicture:=nil; end; end; MDL_MAIN.SetActivationRSReport(False); report.PrepareReport; if FixedFileName<>'' then FileName:=FixedFileName else FileName:='Stampa_' + rsREPORTREP_ID.AsString + '_' + FormatDateTime('yyyymmddhhnnzzz.zzz', Now()); case Modalita of 0://PDF begin if FixedFileName='' then FileName:=FileName + '.pdf'; ExpPDF.FileName := FileName; if FixedFilePath<>'' then ExpPDF.DefaultPath := FixedFilePath + '/' else ExpPDF.DefaultPath := SRV_MAIN.LocalCachePath; // Export Path; report.Export(ExpPDF); FileName:= SRV_MAIN.LocalCachePath + FileName; FileName:=Copy(FileName,Pos(SRV_MAIN.CacheFolderPath,FileName)+length(SRV_MAIN.CacheFolderPath),1000000); FileReport:=FileName; end; 1://XLSX begin ExpExcel.ShowDialog:=False; ExpExcel.ShowProgress:=False; ExpExcel.OpenAfterExport:=False; FileName:=FileName + '.xls'; ExpExcel.FileName := FileName; ExpExcel.DefaultPath := SRV_MAIN.LocalCachePath; // Export Path; report.Export(ExpExcel); FileName:= SRV_MAIN.LocalCachePath + FileName; FileName:=Copy(FileName,Pos(SRV_MAIN.CacheFolderPath,FileName)+length(SRV_MAIN.CacheFolderPath),1000000); FileReport:=FileName; end; 2://PRINT begin report.PrintOptions.ShowDialog:=True; report.Print; end; end; MDL_MAIN.SetActivationRSReport(True); finally CloseDS; end; end; procedure TMDL_REPORT.CaricaDataset; begin if rsREPORTREP_NDATASET.AsInteger>=1 then report.EnabledDataSets.Add(MDL_MAIN.CreateDBReport(1)); if rsREPORTREP_NDATASET.AsInteger>=2 then report.EnabledDataSets.Add(MDL_MAIN.CreateDBReport(2)); if rsREPORTREP_NDATASET.AsInteger>=3 then report.EnabledDataSets.Add(MDL_MAIN.CreateDBReport(3)); if rsREPORTREP_NDATASET.AsInteger>=4 then report.EnabledDataSets.Add(MDL_MAIN.CreateDBReport(4)); if rsREPORTREP_NDATASET.AsInteger>=5 then begin report.EnabledDataSets.Add(MDL_MAIN.CreateDBReport(5)); if rsREPORTREP_NDATASET.AsInteger>=6 then report.EnabledDataSets.Add(MDL_MAIN.CreateDBReport(6)); if rsREPORTREP_NDATASET.AsInteger>=7 then report.EnabledDataSets.Add(MDL_MAIN.CreateDBReport(7)); if rsREPORTREP_NDATASET.AsInteger>=8 then report.EnabledDataSets.Add(MDL_MAIN.CreateDBReport(8)); if rsREPORTREP_NDATASET.AsInteger>=9 then report.EnabledDataSets.Add(MDL_MAIN.CreateDBReport(9)); if rsREPORTREP_NDATASET.AsInteger>=10 then report.EnabledDataSets.Add(MDL_MAIN.CreateDBReport(10)); end; Can you give me some indication on how to solve the problem? Thank you Marco Link to comment Share on other sites More sharing options...
Abaksoft Posted September 17, 2021 Share Posted September 17, 2021 3 hours ago, Marco1979 said: Hi everyone, I don't write much in this forum but I follow all the problems that are exposed and you have often solved me many problems about creating code with unigui objects. I wanted to ask you a question about a problem that I just can't solve: I use Fast Report to create reports. I set all the parameters correctly (so it seems to me), even taking inspiration from the Demo projects and from the advice of other users. Only that the first time the report is loaded, it shows a blank page, just the page with the report header, with no data. If I reload the report again, the data also comes out and the report is displayed correctly. Below is the procedure created to generate the report: procedure TMDL_REPORT.CaricaReport(ID,Modalita:Integer;var FileReport:String;ParametriFissi:String;FixedFileName,FixedFilePath:String); var I,contImg:Integer; FileName,nameImg:String; appoPicture:TfrxPictureView; begin CloseDS; //Carico il report dalla tabella LoadDati(ID); report.Destroy; report:=TfrxReport.Create(Self); report.EngineOptions.SilentMode := True; report.EngineOptions.EnableThreadSafe := True; report.EngineOptions.DestroyForms := False; report.PrintOptions.ShowDialog := False; report.ShowProgress:=false; report.LoadFromFile(SRV_MAIN.StartPath+'images\report\' + rsREPORTREP_CODICE.AsString + '.fr3'); //Caricamento parametri di avvio report if (rsPARVISPAR_VISIBLE.AsString='1') then if DGL_REPORT_PARAMETER.GetParametri(rsPARAMETER,rsREPORTREP_NOME.AsString,ID)=False then Exit; try //Esecuzione STORED LoadStoredReport(ParametriFissi); report.EnabledDataSets.Clear; //Caricamento dataset CaricaDataset; AssignLinkFields; //Inizializzo i valori delle variabili if (report.Variables.Count>0) and (rsPARAMETER.RecordCount>0) then begin for I:=0 to report.Variables.Count-1 do begin //Ricerco nella tabella rsPARAMETER.First; while not rsPARAMETER.Eof do begin if rsPARAMETERPAR_NOME.Value=report.Variables.Items[I].Name then begin //Assegno il valore if (rsPARAMETERPAR_NASCOSTO.Value) and (rsPARAMETERPAR_DISPLAYDEF.AsString<>'') then report.Variables.Items[I].Value:='''' + rsPARAMETERPAR_DISPLAYDEF.AsString + '''' else if (rsPARAMETERPAR_NASCOSTO.Value=False) and (rsPARAMETERPAR_VALORE.AsString<>'') then report.Variables.Items[I].Value:='''' + rsPARAMETERPAR_VALORE.AsString + ''''; end; rsPARAMETER.Next; end; end; end; //caricamento immagini loghi for contImg := 0 to report.ComponentCount-1 do begin if report.Components[contImg] is TfrxPictureView then begin nameImg:=TfrxPictureView(report.Components[contImg]).Name; //ricerco nella cartella immagine se è presente il file con questo nome if FileExists(SRV_MAIN.StartPath+'images\report\'+nameImg+'.png') then begin AppoPicture:=report.FindObject(nameImg) as TfrxPictureView; if appoPicture<>nil then appoPicture.Picture.LoadFromFile(SRV_MAIN.StartPath+'images\report\'+nameImg+'.png'); end; appoPicture:=nil; end; end; MDL_MAIN.SetActivationRSReport(False); report.PrepareReport; if FixedFileName<>'' then FileName:=FixedFileName else FileName:='Stampa_' + rsREPORTREP_ID.AsString + '_' + FormatDateTime('yyyymmddhhnnzzz.zzz', Now()); case Modalita of 0://PDF begin if FixedFileName='' then FileName:=FileName + '.pdf'; ExpPDF.FileName := FileName; if FixedFilePath<>'' then ExpPDF.DefaultPath := FixedFilePath + '/' else ExpPDF.DefaultPath := SRV_MAIN.LocalCachePath; // Export Path; report.Export(ExpPDF); FileName:= SRV_MAIN.LocalCachePath + FileName; FileName:=Copy(FileName,Pos(SRV_MAIN.CacheFolderPath,FileName)+length(SRV_MAIN.CacheFolderPath),1000000); FileReport:=FileName; end; 1://XLSX begin ExpExcel.ShowDialog:=False; ExpExcel.ShowProgress:=False; ExpExcel.OpenAfterExport:=False; FileName:=FileName + '.xls'; ExpExcel.FileName := FileName; ExpExcel.DefaultPath := SRV_MAIN.LocalCachePath; // Export Path; report.Export(ExpExcel); FileName:= SRV_MAIN.LocalCachePath + FileName; FileName:=Copy(FileName,Pos(SRV_MAIN.CacheFolderPath,FileName)+length(SRV_MAIN.CacheFolderPath),1000000); FileReport:=FileName; end; 2://PRINT begin report.PrintOptions.ShowDialog:=True; report.Print; end; end; MDL_MAIN.SetActivationRSReport(True); finally CloseDS; end; end; procedure TMDL_REPORT.CaricaDataset; begin if rsREPORTREP_NDATASET.AsInteger>=1 then report.EnabledDataSets.Add(MDL_MAIN.CreateDBReport(1)); if rsREPORTREP_NDATASET.AsInteger>=2 then report.EnabledDataSets.Add(MDL_MAIN.CreateDBReport(2)); if rsREPORTREP_NDATASET.AsInteger>=3 then report.EnabledDataSets.Add(MDL_MAIN.CreateDBReport(3)); if rsREPORTREP_NDATASET.AsInteger>=4 then report.EnabledDataSets.Add(MDL_MAIN.CreateDBReport(4)); if rsREPORTREP_NDATASET.AsInteger>=5 then begin report.EnabledDataSets.Add(MDL_MAIN.CreateDBReport(5)); if rsREPORTREP_NDATASET.AsInteger>=6 then report.EnabledDataSets.Add(MDL_MAIN.CreateDBReport(6)); if rsREPORTREP_NDATASET.AsInteger>=7 then report.EnabledDataSets.Add(MDL_MAIN.CreateDBReport(7)); if rsREPORTREP_NDATASET.AsInteger>=8 then report.EnabledDataSets.Add(MDL_MAIN.CreateDBReport(8)); if rsREPORTREP_NDATASET.AsInteger>=9 then report.EnabledDataSets.Add(MDL_MAIN.CreateDBReport(9)); if rsREPORTREP_NDATASET.AsInteger>=10 then report.EnabledDataSets.Add(MDL_MAIN.CreateDBReport(10)); end; Can you give me some indication on how to solve the problem? Thank you Marco Hi Marco, As you know, debuging a problem is to think atomic. Here, your code is so complex to decrypt. Try to buid a simple report and step by step.... you add your specifications. Link to comment Share on other sites More sharing options...
Marco1979 Posted October 5, 2021 Author Share Posted October 5, 2021 On 9/17/2021 at 9:01 PM, Abaksoft said: Hi Marco, As you know, debuging a problem is to think atomic. Here, your code is so complex to decrypt. Try to buid a simple report and step by step.... you add your specifications. Hi, I simplified the procedure by putting all the steps in a single procedure procedure TMDL_REPORT.CaricaReport(ID,Modalita:Integer;var FileReport:String;ParametriFissi:String;FixedFileName,FixedFilePath:String); var FileName:String; begin report.Destroy; report:=TfrxReport.Create(Self); report.EngineOptions.SilentMode := True; report.EngineOptions.EnableThreadSafe := True; report.EngineOptions.DestroyForms := False; report.PrintOptions.ShowDialog := False; report.ShowProgress:=false; report.LoadFromFile(SRV_MAIN.StartPath+'images\report\' + rsREPORTREP_CODICE.AsString + '.fr3'); //Esecuzione STORED LoadStoredReport(ParametriFissi); report.EnabledDataSets.Clear; //Caricamento dataset if rsREPORTREP_NDATASET.AsInteger>=1 then report.EnabledDataSets.Add(MDL_MAIN.Dati1); if rsREPORTREP_NDATASET.AsInteger>=2 then report.EnabledDataSets.Add(MDL_MAIN.Dati2); if rsREPORTREP_NDATASET.AsInteger>=3 then report.EnabledDataSets.Add(MDL_MAIN.Dati3); if rsREPORTREP_NDATASET.AsInteger>=4 then report.EnabledDataSets.Add(MDL_MAIN.Dati4); if rsREPORTREP_NDATASET.AsInteger>=5 then report.EnabledDataSets.Add(MDL_MAIN.Dati5); if rsREPORTREP_NDATASET.AsInteger>=6 then report.EnabledDataSets.Add(MDL_MAIN.Dati6); if rsREPORTREP_NDATASET.AsInteger>=7 then report.EnabledDataSets.Add(MDL_MAIN.Dati7); if rsREPORTREP_NDATASET.AsInteger>=8 then report.EnabledDataSets.Add(MDL_MAIN.Dati8); if rsREPORTREP_NDATASET.AsInteger>=9 then report.EnabledDataSets.Add(MDL_MAIN.Dati9); if rsREPORTREP_NDATASET.AsInteger>=10 then report.EnabledDataSets.Add(MDL_MAIN.Dati10); FileName:='Stampa_' + rsREPORTREP_ID.AsString + '_' + FormatDateTime('yyyymmddhhnnzzz.zzz', Now()); FileName:=FileName + '.pdf'; ExpPDF.FileName := FileName; ExpPDF.DefaultPath := SRV_MAIN.LocalCachePath; // Export Path; report.Export(ExpPDF); FileName:= SRV_MAIN.LocalCachePath + FileName; FileName:=Copy(FileName,Pos(SRV_MAIN.CacheFolderPath,FileName)+length(SRV_MAIN.CacheFolderPath),1000000); FileReport:=FileName; end; The MDL_MAIN module is the MainModule in which I declared both the ClientDataset and the frxDBDataset connected to them. Running the application in localhost, I have no problems. when it is online and used by multiple users, it happens, but not always, that the reports come out empty or even with data that does not correspond to those recalled in the query. Am I wrong in declaring the TClientDataset and TfrxDBDataset components? Is it right to declare them on MainModule which should be the only module for the active session? However the module that performs the creation of the report (the one I posted) is created and destroyed at each call. I hope I was clearer. Thanks and I look forward to your response. Marco Link to comment Share on other sites More sharing options...
Marco1979 Posted October 13, 2021 Author Share Posted October 13, 2021 Hello, I'm sorry I still haven't received any answers that help me. However, I wanted to add that the application just in these days continues to process reports showing inside them the data of another report, ie the data obtained from the stored procedure do not coincide with those represented in the report. I remember that mine is a server application used simultaneously by many users. I hope I can get some suggestions. Hello. Marco Link to comment Share on other sites More sharing options...
Sherzod Posted October 13, 2021 Share Posted October 13, 2021 Hello, First of all please specify, which build and edition of UniGUI are you using? Link to comment Share on other sites More sharing options...
Marco1979 Posted October 13, 2021 Author Share Posted October 13, 2021 Hello, 1.90.0.1551 Link to comment Share on other sites More sharing options...
Sherzod Posted October 13, 2021 Share Posted October 13, 2021 14 minutes ago, Marco1979 said: 1.90.0.1551 Trial edition? If not, please adjust your forum email address first. Link to comment Share on other sites More sharing options...
Marco1979 Posted October 13, 2021 Author Share Posted October 13, 2021 no, I use a licensed version. The email on which the license is active is not the same one on which I registered. Is it a problem? Link to comment Share on other sites More sharing options...
Sherzod Posted October 13, 2021 Share Posted October 13, 2021 19 minutes ago, Marco1979 said: The email on which the license is active is not the same one on which I registered. Is it a problem? Yes. Link to comment Share on other sites More sharing options...
Marco1979 Posted October 13, 2021 Author Share Posted October 13, 2021 Ok. I changed the forum account email Link to comment Share on other sites More sharing options...
Marco1979 Posted October 19, 2021 Author Share Posted October 19, 2021 Hi, sorry for the insistence, but i hope to solve this problem? Link to comment Share on other sites More sharing options...
Abaksoft Posted October 20, 2021 Share Posted October 20, 2021 On 10/19/2021 at 8:03 AM, Marco1979 said: Hi, sorry for the insistence, but i hope to solve this problem? Hi Marco, Here is in attachment an example, for using FR with Unigui (without any problem). Important : you have to delete the temp file onClose event. procedure TfrmFastReport.UniFormClose(Sender: TObject; var Action: TCloseAction); begin //1. Important try DeleteFile(fFile_Temp); Except end; //2. No ! must be open // DBMyDataSet.Close; end; Using_FastReport.zip Link to comment Share on other sites More sharing options...
Marco1979 Posted October 20, 2021 Author Share Posted October 20, 2021 Hi ABAKSOFT, meanwhile thanks for the sample file. However I use a DataModule with all the reporting and data loading functions of the datasets (the one I posted in the previous messages). I call this DataModule to have the file created and then I destroy it; returning the path of the file, I load the report using the function "UniSession.BrowserWindow" Do you think it is better to show the file in the same form in which it is created and then destroy everything on closing? Please note that this program is used by multiple users at the same time (obviously each with their own session). Thanks!!! Marco Link to comment Share on other sites More sharing options...
Marco1979 Posted October 29, 2021 Author Share Posted October 29, 2021 Hi, can you tell me something about the request I made? Thanks. Marco Link to comment Share on other sites More sharing options...
Abaksoft Posted October 29, 2021 Share Posted October 29, 2021 3 hours ago, Marco1979 said: Hi, can you tell me something about the request I made? Thanks. Marco Hello Marco, I am sure that you can adapt your case, with what i sent you. Just replace DBMyDataSet (on the sample above) by your dataset. Regards... Link to comment Share on other sites More sharing options...
Roberto Nicchi Posted October 29, 2021 Share Posted October 29, 2021 Try to create a self contained demo app that is possible to compile and execute. Instead of a database access use a Tclientdataset. It can happens two things: 1) the demo app is working so it can help you to understand the problem in your main app 2) the demo app shows the problem and you can post it here. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now