Nel caso "1" ci vuole qualcosa tipo questo
E' un po' brutale, ma penso si capiscacodice:function GetInetFile (const fileURL, FileName: String;i_dimensione:integer=0): boolean; const BufferSize = 1024; var hSession, hURL: HInternet; Buffer: array[1..BufferSize] of Byte; BufferLen: DWORD; f: File; sAppName: string; scaricati:integer; begin frmlog.memlog.lines.clear; frmlog.memlog.lines.add('Scaricamento da internet (si può premere STOP)'); if i_dimensione>0 then frmlog.memlog.lines.add( 'Byte da trasferire '+(numeroconpuntini(i_dimensione))); frmlog.show; salvabtnstop; frmlog.btnstop.enabled:=true; application.processmessages; if i_dimensione>0 then frmlog.pgrprogressototale.max:=i_dimensione; deletefile(pchar(filename)); result := false; scaricati:=0; 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) ; repeat if not frmlog.btnstop.enabled then break; function GetInetFile (const fileURL, FileName: String;i_dimensione:integer=0): boolean; const BufferSize = 1024; var hSession, hURL: HInternet; Buffer: array[1..BufferSize] of Byte; BufferLen: DWORD; f: File; sAppName: string; scaricati:integer; begin frmlog.memlog.lines.clear; frmlog.memlog.lines.add('Scaricamento da internet (si può premere STOP)'); if i_dimensione>0 then frmlog.memlog.lines.add( 'Byte da trasferire '+(numeroconpuntini(i_dimensione))); frmlog.show; salvabtnstop; frmlog.btnstop.enabled:=true; application.processmessages; if i_dimensione>0 then frmlog.pgrprogressototale.max:=i_dimensione; deletefile(pchar(filename)); result := false; scaricati:=0; 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) ; repeat //// ECCOLO QUI if not frmlog.btnstop.enabled then break; ///////////////// InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen) ; BlockWrite(f, Buffer, BufferLen); if i_dimensione>0 then begin frmlog.memlog.lines[2]:= 'Scaricamento '+(numeroconpuntini(scaricati))+' bytes'; frmlog.pgrprogressototale.position:=scaricati; end else frmlog.memlog.lines[1]:= 'Scaricamento '+trim(numeroconpuntini(scaricati))+' bytes'; application.processmessages; scaricati:=scaricati+bufferlen; application.processmessages; until BufferLen = 0; CloseFile(f) ; result := True; finally InternetCloseHandle(hURL) end finally InternetCloseHandle(hSession) end; if not frmlog.btnstop.enabled then begin deletefile(pchar(filename)); end; frmlog.btnstop.enabled:=true; ripristinabtnstop; frmlog.hide; end; InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen) ; BlockWrite(f, Buffer, BufferLen); if i_dimensione>0 then begin frmlog.memlog.lines[2]:= 'Scaricamento '+(numeroconpuntini(scaricati))+' bytes'; frmlog.pgrprogressototale.position:=scaricati; end else frmlog.memlog.lines[1]:= 'Scaricamento '+trim(numeroconpuntini(scaricati))+' bytes'; application.processmessages; scaricati:=scaricati+bufferlen; application.processmessages; until BufferLen = 0; CloseFile(f) ; result := True; finally InternetCloseHandle(hURL) end finally InternetCloseHandle(hSession) end; if not frmlog.btnstop.enabled then begin deletefile(pchar(filename)); end; frmlog.btnstop.enabled:=true; ripristinabtnstop; frmlog.hide; end;

Rispondi quotando