I have a While loop where I download a PDF file to a folder on my hard drive and create a window with a TMSFNCWXPDFViewer to display each of these files in separate windows.
But the problem is that in all these windows I create, it only shows the last PDF file.
Something like that:
While NOT Query.EOF do
begin
...
//Here download a file to disk
Show_PDF(File);
Query.Next
end
Show_PDF displays the file in a TMSFNCWXPDFViewer:
IF (File <> '') THEN
FormA.TMSFNCWXPDFViewer1.Visible:= True;
// TMSFNCWXPDFViewer1.LoadFromFile(File); If I put this here, it doesn't show the PDF, I have to put it in the event Initialized
FormA.FormStyle:= fsStayOnTop;
FormA.Show
PROCEDURE TFormA.TMSFNCWXPDFViewer1ViewerInitialized(
Sender: TObject);
BEGIN
TMSFNCWXPDFViewer1.LoadFromFile(File);
END;
Why does it show the last file in all windows? How can I fix this?
It’s not quite clear from your code, do you persist per each TFormA the File you want to load?
As you already noticed, the PDF viewer needs to be initialized first. If you use the same File variable for each viewer, then by the time they initialize, the loop is finished so it points ot the last file.
Could it be an option to introduce a TFormA.PDF property where you can persist the File and load it like that?
It’s unclear what happens in your case. We setup a similar project, but the PDFs are loaded from the disk directly, without downloading. This works fine here.
Are you sure the PDFs are downloaded correctly in your case and the correct path is passed to your form(s)?
What I did is exactly the same; the only difference is the while loop I use to retrieve the files and their names from a database query.
All files are downloaded correctly to the hard drive and the path I passed as a parameter to display the pdf is correct.
When I debug, each screen displays, but the TTMSFNCWXPDFViewer component doesn't show anything. Only after the loop finishes does it display the PDF on each open screen, but it's the last one that was downloaded.
I'm trying to add a delay between each cycle to see if it's a timing issue between operations, but so far I haven't been able to change the result.
I tried it again with a new form, and it works correctly.
I'm going to try to figure out what was causing the problems; so far, it's working fine, so I still don't know what the issue was.