Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Download problem u delphiu

[es] :: Pascal / Delphi / Kylix :: Download problem u delphiu

[ Pregleda: 2688 | Odgovora: 15 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

anon68680

Član broj: 68680
Poruke: 528
213.137.127.*



+14 Profil

icon Download problem u delphiu22.09.2005. u 16:53 - pre 226 meseci
Code:

function TForm1.DownloadFile
(const fileURL, FileName: String): boolean;
const BufferSize = 1024;
var
  hSession, hURL: HInternet;
  Buffer: array[1..BufferSize] of Byte;
  BufferLen: DWORD;
  f: File;
  sAppName: string;
begin
Result:=False;
sAppName := ExtractFileName(Application.ExeName);
hSession := InternetOpen(PChar(sAppName),
                INTERNET_OPEN_TYPE_PRECONFIG,
               nil, nil, 0);
try
  hURL := InternetOpenURL(hSession,
            PChar(fileURL),
            nil,0,0,0);
  try
   AssignFile(f, FileName);
   Rewrite(f,1);
   Gauge1.MaxValue:=BufferLen;
   repeat
    InternetReadFile(hURL, @Buffer,
                     SizeOf(Buffer), BufferLen);
    BlockWrite(f, Buffer, BufferLen);
    Gauge1.Progress:=Gauge1.Progress+1;
   until BufferLen = 0;
   CloseFile(f);
   Result:=True;
  finally
   InternetCloseHandle(hURL)
  end
finally
  InternetCloseHandle(hSession)
end
end;

naisao sam na ovaj cod kada sam trazio neshto sto ce mi omoguciti download nekog filea sa interneta a da pritom mogu prikaziti progress tog downloadovanja u nekom progressbaru. problem je u tome sto se pri startovanju funkcije program zaledi do zavrsetka downloada. Da li neko zna u cemu je problem?
 
Odgovor na temu

Srki_82
Srdjan Tot
Me @ My Home
Ljubljana

Član broj: 28226
Poruke: 1403
82.208.201.*

ICQ: 246436949


+10 Profil

icon Re: Download problem u delphiu22.09.2005. u 22:46 - pre 226 meseci
Negde izmedju repeat until ubaci Application.ProcessMessages
 
Odgovor na temu

reiser

Član broj: 7895
Poruke: 2314



+102 Profil

icon Re: Download problem u delphiu22.09.2005. u 22:47 - pre 226 meseci
Najbolje ispod Gauge1.Progress:=Gauge1.Progress+1; linije

[Ovu poruku je menjao reiser dana 22.09.2005. u 23:47 GMT+1]
 
Odgovor na temu

anon68680

Član broj: 68680
Poruke: 528
213.137.127.*



+14 Profil

icon Re: Download problem u delphiu22.09.2005. u 23:45 - pre 226 meseci
noup idalje imam problema, posto se zavrshi download applikacija pocinje da koci i jos neke gluposti. da li mozda neko zna neku drugu funkciju koja ima progress mogucnost?
 
Odgovor na temu

Srki_82
Srdjan Tot
Me @ My Home
Ljubljana

Član broj: 28226
Poruke: 1403
82.208.201.*

ICQ: 246436949


+10 Profil

icon Re: Download problem u delphiu23.09.2005. u 08:17 - pre 226 meseci
Instaliraj Jedi-VCL komponente... tu imas sve i svasta, a izmedju ostalog i komponente za download.
 
Odgovor na temu

anon68680

Član broj: 68680
Poruke: 528
213.137.127.*



+14 Profil

icon Re: Download problem u delphiu23.09.2005. u 23:19 - pre 226 meseci
pronasao sam download funkciju koja radi:
Code:

function DownloadFile(const Url: string; destFName: string): string;
var
  NetHandle: HINTERNET;
  UrlHandle: HINTERNET;
  Buffer: array[0..1024] of Char;
  BytesRead: dWord;
  f: File;
  i: longint;
begin
  Result := '';
  NetHandle := InternetOpen('Delphi ', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  if Assigned(NetHandle) then  begin
    UrlHandle := InternetOpenUrl(NetHandle, PChar(Url), nil, 0, INTERNET_FLAG_RELOAD, 0);
    if Assigned(UrlHandle) then begin
      FillChar(Buffer, SizeOf(Buffer), 0);
      AssignFile(f, destFName);
      Rewrite(f,1);
      i:=0;
      form3.Gauge2.Maxvalue:=bytesread;
      repeat
        Result := Result + Buffer;
        FillChar(Buffer, SizeOf(Buffer), 0);
        InternetReadFile(UrlHandle, @Buffer, SizeOf(Buffer), BytesRead);
        i:=myFileSize(destFName);
        form3.Gauge2.Progress:=i;
        BlockWrite(f, Buffer, BytesRead);
        Application.ProcessMessages;
      until BytesRead = 0;
      CloseFile(f);
      InternetCloseHandle(UrlHandle);
    end;
  end;
end;

sada kao sto vidite form3.Gauge2.Maxvalue:=bytesread; treba da se zameni sa velicinom filea na serveru odakle se skida. ali kako?

[Ovu poruku je menjao krza dana 24.09.2005. u 00:35 GMT+1]
 
Odgovor na temu

Srki_82
Srdjan Tot
Me @ My Home
Ljubljana

Član broj: 28226
Poruke: 1403
82.208.201.*

ICQ: 246436949


+10 Profil

icon Re: Download problem u delphiu23.09.2005. u 23:42 - pre 226 meseci
Pogledaj kako sam napisao TAutoUpdate komponentu za Delphi 7... mozda ti pomogne.

http://www.elitesecurity.org/tema/136194-ZeusGames-AutoUpdate
 
Odgovor na temu

ivanho
slobodni umetnik
Beograd

Član broj: 28465
Poruke: 73
217.26.75.*



Profil

icon Re: Download problem u delphiu24.09.2005. u 07:48 - pre 226 meseci
Code:

function DownloadFile(strUrlFile, strDestFile: string;
comLabel: TLabel = Nil;
comProgressBar: TProgressBar = Nil
): boolean;
var
  handleNet: HINTERNET;
  handleUrl: HINTERNET;
  arrchBuffer: Array[0..1024] Of Char;
  dwFileSize, dwReserved, dwBytesRead: dWord;
  intNumByte: Integer;
  strReadFile: String;
begin
  Result := false;
  try
    handleNet := InternetOpen(PChar(Application.Title), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
    if Assigned(handleNet) then
      begin
        handleUrl := InternetOpenUrl(handleNet, PChar(strUrlFile), nil, 0, INTERNET_FLAG_RELOAD, 0);
        if Assigned(handleUrl) then
          begin

           // koliko je velik fajl
           arrchBuffer := '';
           dwFileSize := SizeOf(arrchBuffer);
           dwReserved := 0;
           If HttpQueryInfo(handleUrl, HTTP_QUERY_CONTENT_LENGTH, @arrchBuffer, dwFileSize, dwReserved) Then
              dwFileSize := StrToIntDef(arrchBuffer, -1);

           if comLabel <> nil Then
             comLabel.Caption := '0 od 0 bytes';
           if comProgressBar <> nil then
             begin
               comProgressBar.Min:=0;
               comProgressBar.Max:=dwFileSize;
               comProgressBar.Position:=0;
             end;

           FillChar(arrchBuffer, SizeOf(arrchBuffer), 0);
             repeat
               FillChar(arrchBuffer, SizeOf(arrchBuffer), 0);
               InternetReadFile(handleUrl, @arrchBuffer, SizeOf(arrchBuffer), dwBytesRead);
               for intNumByte := 0 To dwBytesRead - 1 Do
                 strReadFile := Concat(strReadFile, arrchBuffer[intNumByte]);

               if comProgressBar <> nil then
                 comProgressBar.Position := Form1.ProgressBar1.Position + StrToInt(IntToStr(dwBytesRead));


               if comLabel <> nil then
               comLabel.Caption := FormatFloat('0,000', Length(strReadFile)) + ' od ' + FormatFloat('0,000', dwFileSize) + ' bytes';

               Application.ProcessMessages;
             until dwBytesRead = 0;


           If Length(strReadFile) > 0 Then
             begin
               If FileExists(strDestFile) Then
                 DeleteFile(PChar(strDestFile));

               with TFileStream.Create(strDestFile, fmCreate) Do
                 try
                   Write(strReadFile[1], Length(strReadFile));
                 finally
                   Free;
                 end;
               result := True;
             end
           else
             result := False;
          end;
      end;
  finally
    InternetCloseHandle(handleUrl);
    InternetCloseHandle(handleNet);
  end;
end;
 
Odgovor na temu

anon68680

Član broj: 68680
Poruke: 528
*.ptt.yu.



+14 Profil

icon Re: Download problem u delphiu24.09.2005. u 12:00 - pre 226 meseci
noup ni ova ne radi... :(
kaze da je file veliki nekih 1000bytes a ustvari je bar 200 000...
 
Odgovor na temu

Srki_82
Srdjan Tot
Me @ My Home
Ljubljana

Član broj: 28226
Poruke: 1403
82.208.201.*

ICQ: 246436949


+10 Profil

icon Re: Download problem u delphiu24.09.2005. u 12:34 - pre 226 meseci
Kao sto rekoh... pogledaj kod za TAutoUpdate i sve ce ti biti jasno. Koristi se TDownLoadURL komponenta koja ide sa Delphi 7.
 
Odgovor na temu

anon68680

Član broj: 68680
Poruke: 528
213.137.127.*



+14 Profil

icon Re: Download problem u delphiu24.09.2005. u 12:42 - pre 226 meseci
da upravo sam je skino samo sto ne znam kako se koristi. ima dve onprogress eventa ne znam koji je koji...
 
Odgovor na temu

Srki_82
Srdjan Tot
Me @ My Home
Ljubljana

Član broj: 28226
Poruke: 1403
82.208.201.*

ICQ: 246436949


+10 Profil

icon Re: Download problem u delphiu24.09.2005. u 12:47 - pre 226 meseci
Znam da ne znas kako se koristi... pogledaj kako se koristi TDownLoadURL komponenta. To je ono sto tebi treba.
 
Odgovor na temu

anon68680

Član broj: 68680
Poruke: 528
213.137.127.*



+14 Profil

icon Re: Download problem u delphiu24.09.2005. u 13:22 - pre 226 meseci
da mislim da sam skuzio vishe manje. ali ne znam zaglavio sam se. evo sta sam uradio:

Code:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtActns, Wininet, ComCtrls, StdCtrls, AutoUpdate;

type
  TForm1 = class(TForm)
    AutoUpdate1: TAutoUpdate;
    ProgressBar1: TProgressBar;
    Button1: TButton;
    procedure AutoUpdate1DownLoadUpdateDataProgress(Sender: TAutoUpdate;
      Progress, ProgressMax: Cardinal; var Cancel: Boolean);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
implementation

{$R *.dfm}

procedure TForm1.AutoUpdate1DownLoadUpdateDataProgress(Sender: TAutoUpdate;
  Progress, ProgressMax: Cardinal; var Cancel: Boolean);
begin
ProgressBar1.Max:=progressmax;
ProgressBar1.Position:=progress;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
AutoUpdate1.UpdateAddress:='http://users.cjb.net/netwalker/';
AutoUpdate1.UpdateDataFile:='chbook.ini';
AutoUpdate1.DownLoadUpdateData;
end;

end.

e sad ovde u eventu button1click treba da odredim verovatno gde file da ide a ne znam kako?
 
Odgovor na temu

Srki_82
Srdjan Tot
Me @ My Home
Ljubljana

Član broj: 28226
Poruke: 1403
82.208.201.*

ICQ: 246436949


+10 Profil

icon Re: Download problem u delphiu24.09.2005. u 17:35 - pre 226 meseci
Hehe... nemoj da koristis TAutoUpdate komponentu za obicno skidanje fajla. Koristi samo TDownLoadURL komponentu. Imas help za nju u Delphi-u.
Ako ti treba bas autoupdate funkcija za tvoj program posalji mi pm pa cu ti objasniti kako se koristi.
 
Odgovor na temu

Nemanja Avramović
Engineering Manager
MENU Technologies
Beograd, Srbija

Član broj: 32202
Poruke: 4391
*.yu1.net.

Sajt: https://avramovic.info


+46 Profil

icon Re: Download problem u delphiu27.09.2005. u 17:16 - pre 226 meseci
ako nisi resio problem, evo:

dodas u uses URLMon

i onda ubacis sledecu funkciju:

Code:

function DownloadFile(source, destination: string): boolean;
var
SourceFile, LocalFile: string;
begin
SourceFile := source;
LocalFile := destination;
if URLDownloadToFile(nil, PChar(SourceFile), PChar(LocalFile), 0, nil) = 0 then
  result := true
else
  result := false;
end;



Pa pozivas:

Code:

if not DownloadFile('http://www.sajt.com/path/to/file.ext','c:\file.ext') then
  showmessage('Ne mogu da skinem fajl')
else
 uradinestosafajlom; // ;)
end;


p.s. mislim da sa ovim ne mozes da 'uhvatis' progress kod downloada...
Laravel Srbija.

[NE PRUŽAM PODRŠKU ZA PHP PREKO PRIVATNIH PORUKA!]
 
Odgovor na temu

anon68680

Član broj: 68680
Poruke: 528
213.137.127.*



+14 Profil

icon Re: Download problem u delphiu27.09.2005. u 18:45 - pre 226 meseci
hvala ali meni treba download sa progressom a ovu funkciju vec imam
 
Odgovor na temu

[es] :: Pascal / Delphi / Kylix :: Download problem u delphiu

[ Pregleda: 2688 | Odgovora: 15 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.