Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Copying a resource using streams only works once


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Dec 19, 2017 2:26 PM Last Post By: Francisco Peris Threads: [ Previous | Next ]
Francisco Peris

Posts: 91
Registered: 1/5/15
Copying a resource using streams only works once  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 22, 2017 2:22 PM
In my app there are several pdf files that the can read on a webbrowser, clicking on a button. Each file has its associated button.

In order to have the pdf files updated for future versions, I copy the pdf file from the resource each time the user clicks on the buttton. The code follows:

TResourceStream.Create(HInstance, 'pdf_help1', RT_RCDATA);
 
DestinationName := system.IOUtils.TPath.GetDocumentsPath+ PathDelim+ 'pdf_copied.pdf';
 
try
    dStream := TFileStream.Create(DestinationName, fmCreate);
    try
      dStream.CopyFrom(Stream, 0);
    finally
      dStream.Free;
    end;
  finally
    Stream.Free;
  end;
 
WebBrowser1.Navigate('file://' + DestinationName);


This is the same code for each button for reading the pdf file. It only changes the name of the pdf file associated to that button.

Problem. It only works with the first button that the user clicks on. I mean

app starts.
click on Button A. The pdf file is shown on the browser
click on Button B. Error: The specified file was not found.

Another try, after reinstalling the app.
app starts.
click on Button B. The pdf file is shown on the browser
click on Button A. Error: The specified file was not found.
click on Button C. Error: The specified file was not found.

Why the code only works for the first button clicked?

Thanks is advance
Steph van Hooft

Posts: 3
Registered: 4/18/02
Re: Copying a resource using streams only works once  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 6, 2017 12:15 AM   in response to: Francisco Peris in response to: Francisco Peris
I don't have a solution, but I think I have the same problem:

See here: https://forums.embarcadero.com/thread.jspa?threadID=252540
Francisco Peris

Posts: 91
Registered: 1/5/15
Re: Copying a resource using streams only works once  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 19, 2017 2:26 PM   in response to: Steph van Hooft in response to: Steph van Hooft
Steph van Hooft wrote:
I don't have a solution, but I think I have the same problem:

See here: https://forums.embarcadero.com/thread.jspa?threadID=252540

Finally I created a stream for each file. It seems the only solution, in my case.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02