Thema: Delphi Bilder herunterladen

Einzelnen Beitrag anzeigen

djpaull
(Gast)

n/a Beiträge
 
#4

Re: Bilder herunterladen

  Alt 2. Sep 2008, 10:25
Ich weiss nicht, ob dich das weiter bringt, aber ... Hier ist von meinem Browser. K.A woher ich den hab.

Delphi-Quellcode:
procedure tform1.DL; // Hier Startet man den Download
var
  Savedir,Webdir,Filename,Fileext: String;
  url,ziehl: pchar;
  cDownStatus : cDownloadStatusCallback;
  x,y:integer;
begin
  abort:=false;
  x:=0;
  y:=1;
  cDownStatus := cDownloadStatusCallBack.Create;
  Savedir:=edt1.Text;
  //createdir(ziehl);
  //edt2.Text:=ziehl;
  for i := 0 to Listbox2.items.Count - 1 do //listbox ist die Liste mit bildern
  if abort=false then
  begin
    Application.ProcessMessages;
    url:=pchar(listbox2.Items.Strings[i]);


    //Webdir:=getcurrentwb.LocationName;
    Filename:=ExtractURLPath(listbox2.Items.Strings[i]);
    Fileext:=extractfileext(listbox2.Items.Strings[i]);
    ziehl:=pchar(Savedir + '\' + filename{+ inttostr(i+1)'\' + webdir +  + '.' }+ fileext);
    edt2.Text:=ziehl;
    URLDownloadToFile(nil, url, ziehl, 0 , CDownStatus);
    x:=x+1;
    statusbar1.Panels[3].Text:=inttostr(x)+' Datei(en) Runtergeladen';
    progressbar2.Position:=y;
    y:=y+1;
    edt2.Clear;
  end
  else
  break;
end;

// Das muss auch noch rein
// Frag mich nicht was was ist :-)

function cDownloadStatusCallback._AddRef: Integer;
begin
  Result := 0;
end;

function cDownloadStatusCallback._Release: Integer;
begin
  Result := 0;
end;

function cDownloadStatusCallback.QueryInterface(const IID: TGUID; out Obj): HResult;
begin
  if(GetInterface(IID,Obj)) then
  begin
    Result := 0
  end else
  begin
    Result := E_NOINTERFACE;
  end;
end;

function cDownloadStatusCallback.OnStartBinding(dwReserved: DWORD; pib: IBinding): HResult;
begin
  Result := S_OK;
end;

function cDownloadStatusCallback.GetPriority(out nPriority): HResult;
begin
  Result := S_OK;
end;

function cDownloadStatusCallback.OnLowResource(reserved: DWORD): HResult;
begin
  Result := S_OK;
end;

function cDownloadStatusCallback.OnStopBinding(hresult: HResult; szError: LPCWSTR): HResult; stdcall;
begin
  Result := S_OK;
end;

function cDownloadStatusCallback.GetBindInfo(out grfBINDF: DWORD; var bindinfo: TBindInfo): HResult; stdcall;
begin
  Result := S_OK;
end;

function cDownloadStatusCallback.OnDataAvailable(grfBSCF: DWORD; dwSize: DWORD; formatetc: PFormatEtc; stgmed: PStgMedium): HResult;
begin
  Result := S_OK;
end;

function cDownloadStatusCallback.OnObjectAvailable(const iid: TGUID; punk: IUnknown): HResult; stdcall;
begin
  Result := S_OK;
end;

function cDownloadStatusCallback.OnProgress(ulProgress, ulProgressMax, ulStatusCode: ULONG; szStatusText: LPCWSTR): HResult;
begin
  case ulStatusCode of
    BINDSTATUS_FINDINGRESOURCE:
    begin
      form1.StatusBar1.Panels[2].Text := 'Datei wurde gefunden...';
      if (usercancel) then
      begin
        Result := E_ABORT;
        exit;
      end;
    end;
    BINDSTATUS_CONNECTING:
    begin
      form1.StatusBar1.Panels[2].Text := 'Es wird verbunden...';
      if (usercancel) then
      begin
        Result := E_ABORT;
        exit;
      end;
    end;
    BINDSTATUS_BEGINDOWNLOADDATA:
    begin
      Form1.progressbar1.Position := 0;
      form1.ProgressBar2.Max:=form1.ListBox2.Items.Count;
      //Form1.progressbar2.Position := 0;
      form1.StatusBar1.Panels[2].Text := 'Der Download wurde gestartet...';
      if (UserCancel) then
      begin
        Result := E_ABORT;
        exit;
      end;
    end;
    BINDSTATUS_DOWNLOADINGDATA:
    begin
      Form1.progressbar1.Position := MulDiv(ulProgress,100,ulProgressMax);
      //form1.ProgressBar2.Position := MulDiv(ulProgress,100,ulProgressMax);
      form1.StatusBar1.Panels[2].Text := 'Datei wird heruntergeladen...';
      if (UserCancel) then
      begin
        Result := E_ABORT; exit;
      end;
    end;
    BINDSTATUS_ENDDOWNLOADDATA:
    begin
      form1.StatusBar1.Panels[2].Text := 'Download wurde beendet...';
    end;
  end;
  Application.ProcessMessages;

  Result := S_OK;
end;
Aufrufen kann man sie so
Delphi-Quellcode:
procedure TForm2.ButtonDLClick(Sender: TObject);
begin
DL;
end;
Ich hoffe, das hilft jemandem.
  Mit Zitat antworten Zitat