Link to home
Start Free TrialLog in
Avatar of Cesario Lababidi
Cesario LababidiFlag for Germany

asked on

UrlDownloadToFile & IBindStatusCallback

Hello Experts ;-)

I´m looking for a working exmaple how to use IBindStatusCallBack with UrlDownloadFile?

TIA

Cesario
Avatar of PeterLarsen
PeterLarsen

What components are you using ?
ASKER CERTIFIED SOLUTION
Avatar of Cynna
Cynna

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of simonet
Nice example, Cynna !
;) Thanks simonet.
Avatar of Cesario Lababidi

ASKER

Cynna, great example

1000 Thanx

Cesario
cynna,

do you have any idea how to cancel the download ?
2000 welcomes :))

OnProgress is callback function that is periodically called during download.
You can tell it through OnProgress result to abort operation. Just exit with E_ABORT result instead S_OK.

For the sake of simplicity I modified my previous example to cancel download if file is greater the 15kb. You should, of course, use class flag variable or add method or...<zillion other ways> to choose when to return E_ABORT.
OK, replace old handler with this version:

function TBindStatusCallback.OnProgress(ulProgress, ulProgressMax,
  ulStatusCode: ULONG; szStatusText: LPCWSTR): HResult;
begin
  // Do something, for example, show progress:
  Form1.Caption:='Downloaded: '+IntToStr(ulProgress) +' bytes';
  Result := S_OK;
  // Place some abort flag here. For demo purpose here, cancel after 15K:
  if ulProgress> 15000 then begin
     Result := E_ABORT;
     Form1.Caption:='Download aborted!'
  end;
end;