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