Accepted Answer from Cynna <br>Date: 09/04/2002 05:15AM PDT<br>Grade: A<br> Accepted Answer <br><br><br>This is a simple class based on IBindStatusCallback. It's placed<br>in a separate unit. For demo purposes, OnProgress handler is implemented,<br>so that when download is started, progress will be shown in Form1 caption.<br>(I assumed you have Unit1/Form1).<br><br>1. Create new unit and overwrite it with this:<br><br><br>unit BindStatusCallback;<br>// Implementation of TBindStatusCallback<br><br>interface<br><br>uses SysUtils, Windows, UrlMon, ActiveX;<br><br>type TBindStatusCallback = class(TObject, IBindStatusCallback)<br> protected<br> FRefCount: Integer;<br> // IUnknown<br> function QueryInterface(const IID: TGUID; out Obj): Integer; stdcall;<br> function _AddRef: Integer; stdcall;<br> function _Release: Integer; stdcall;<br> public<br> // IBindStatusCallback<br> function OnStartBinding(dwReserved: DWORD; pib: IBinding): HResult; stdcall;<br> function GetPriority(out nPriority): HResult; stdcall;<br> function OnLowResource(reserved: DWORD): HResult; stdcall;<br> function OnProgress(ulProgress, ulProgressMax, ulStatusCode: ULONG;<br> szStatusText: LPCWSTR): HResult; stdcall;<br> function OnStopBinding(hresult: HResult; szError: LPCWSTR): HResult; stdcall;<br> function GetBindInfo(out grfBINDF: DWORD; var bindinfo: TBindInfo): HResult; stdcall;<br> function OnDataAvailable(grfBSCF: DWORD; dwSize: DWORD; formatetc: PFormatEtc;<br> stgmed: PStgMedium): HResult; stdcall;<br> function OnObjectAvailable(const iid: TGUID; punk: IUnknown): HResult; stdcall;<br> end;<br><br>implementation<br><br>{ TBindStatusCallback }<br><br>uses Unit1; // where Form1 is<br><br>function TBindStatusCallback.QueryInterface(const IID: TGUID;<br> out Obj): Integer;<br>begin<br> if GetInterface(IID, Obj) then Result := S_OK<br> else Result := E_NOINTERFACE;<br>end;<br><br>function TBindStatusCallback._AddRef: Integer;<br>begin<br> Inc(FRefCount);<br> Result := FRefCount;<br>end;<br><br>function TBindStatusCallback._Release: Integer;<br>begin<br> Dec(FRefCount);<br> Result := FRefCount;<br>end;<br><br>function TBindStatusCallback.GetBindInfo(out grfBINDF: DWORD;<br> var bindinfo: TBindInfo): HResult;<br>begin<br> Result := E_NOTIMPL;<br>end;<br><br>function TBindStatusCallback.GetPriority(out nPriority): HResult;<br>begin<br> Result := E_NOTIMPL;<br>end;<br><br>function TBindStatusCallback.OnDataAvailable(grfBSCF, dwSize: DWORD;<br> formatetc: PFormatEtc; stgmed: PStgMedium): HResult;<br>begin<br> Result := E_NOTIMPL;<br>end;<br><br>function TBindStatusCallback.OnLowResource(reserved: DWORD): HResult;<br>begin<br> Result := E_NOTIMPL;<br>end;<br><br>function TBindStatusCallback.OnObjectAvailable(const iid: TGUID;<br> punk: IUnknown): HResult;<br>begin<br> Result := E_NOTIMPL;<br>end;<br><br>function TBindStatusCallback.OnStartBinding(dwReserved: DWORD;<br> pib: IBinding): HResult;<br>begin<br> Result := E_NOTIMPL;<br>end;<br><br>function TBindStatusCallback.OnStopBinding(hresult: HResult;<br> szError: LPCWSTR): HResult;<br>begin<br> Result := E_NOTIMPL;<br>end;<br><br>function TBindStatusCallback.OnProgress(ulProgress, ulProgressMax,<br> ulStatusCode: ULONG; szStatusText: LPCWSTR): HResult;<br>begin<br> // Do something on main form- for example, show progress:<br> Form1.Caption:='Downloaded: '+IntToStr(ulProgress) +' bytes';<br> Result := S_OK;<br>end;<br><br><br>end.<br><br><br><br>-------------------------------------------------------------------------------<br><br>2. In Unit1 :<br><br><br>uses ...., BindStatusCallback, UrlMon;<br><br>type<br> TForm1 = class(TForm)<br><br> // ... blah, blah ...<br><br> end;<br><br>var<br> Form1: TForm1;<br> bsc: TBindStatusCallback; // in unit BindStatusCallback<br><br> // ... your code ...<br><br> procedure TForm1.FormCreate(Sender: TObject);<br> begin<br> bsc:=TBindStatusCallback.Create;<br> end;<br><br> // ... your code ...<br><br> // DEMO:<br> //----------<br> procedure TForm1.Button1Click(Sender: TObject);<br> begin<br> URLDownloadToFile(nil,<br> 'http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20349921.html',<br> 'c:/ee.html', 0 , bsc);<br> end;