Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Detect when a TBrowser instance has downloaded a file
Tue, Sep 10 2024 8:06 AMPermanent Link

Graeme Keast

Hi

My application uses a TBrowser component to download a file by using the following:

  Browser.URL:= 'GetPDFFile'

where the URL returns, in my case, a PDF file.

When the file has been downloaded I get the choice of either opening or saving the downloaded file or cancelling the request.

Is there any way I can detect when the file has finished downloading, specifically when the user chooses Open, Save or Cancel. I need to do some processing at this point in time.

I have tried all the events for the TBrowser component but it seems as though these events are never triggered.

Thanks in advance

Graeme
Tue, Sep 10 2024 5:16 PMPermanent Link

erickengelke

Avatar

Graeme Keast wrote:
> My application uses a TBrowser component to download a file by using the following:
>  Browser.URL:= 'GetPDFFile'
>
>where the URL returns, in my case, a PDF file.

> Is there any way I can detect when the file has finished downloading, specifically when the user chooses Open,
> Save or Cancel. I need to do some processing at this point in time.

I have to ask more questions:

Are you doing post processing in your Web application or in a different user program?  Are you just putting up a message saying the file is downloaded?  

Do you want to view it in the TBrowser or do you want to save it to the filesystem?  

Erick
EWB Programming Books and Nice Component Library
See my EWB BLOG posts, at:
http://www.erickengelke.com
Tue, Sep 10 2024 5:41 PMPermanent Link

erickengelke

Avatar


Graeme Keast wrote:
> My application uses a TBrowser component to download a file by using the following:
>  Browser.URL:= 'GetPDFFile'
>
>where the URL returns, in my case, a PDF file.

First off, don't try to support IE, the built-in browser in EWB.

You may have to experiment.  If you are in a bind, the following kludge returns PDF if the browser has loaded a PDF, it works in Safari, Chrome and Firefox.  


procedure TForm1.Timer1Timer(Sender: TObject);
var
 s: string;
 v : variant;
begin
 try
    v := Browser1.Document;
    s := Browser1.DocumentText;

 except
    s := 'unknown';

 end;
 if ( v = nil ) or ( pos('pdf',s) > 0 ) then
    s := 'PDF'
 else
    s := 'empty';
 Label1.Caption := s;

end;
EWB Programming Books and Nice Component Library
See my EWB BLOG posts, at:
http://www.erickengelke.com
Image