Autor Beitrag
cheve
Hält's aus hier
Beiträge: 5



BeitragVerfasst: Fr 30.09.05 15:34 
Hallo,

Bisher habe ich folgenden Code verwendet, um Dateien aus dem Netz zuladen.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
function GetInetFile(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,
               nilnil0);
 try
  hURL := InternetOpenURL(hSession,
            PChar(fileURL),
            nil,0,0,0);
  try
   AssignFile(f, FileName);
   Rewrite(f,1);
   repeat
    InternetReadFile(hURL, @Buffer,
                     SizeOf(Buffer), BufferLen);
    BlockWrite(f, Buffer, BufferLen)
   until BufferLen = 0;
   CloseFile(f);
   Result:=True;
  finally
   InternetCloseHandle(hURL)
  end
 finally
  InternetCloseHandle(hSession)
 end
end;


Nun ist mir aber aufgefallen, dass für kleine und viele Datein, wie z.B. Bilder, viel zu viel Zeit beansprucht wird (=langsam). Kennt jemand eine schnellere Möglichkeit/Code? (Meine bisherigen Kenntnisse enden größtenteils hier bei diesem Code)

Gruß
cheve
uall@ogc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1826
Erhaltene Danke: 11

Win 2000 & VMware
Delphi 3 Prof, Delphi 7 Prof
BeitragVerfasst: Fr 30.09.05 15:38 
sollte schon relativ schnell gehen, vielleicht einfach mal BufferSize erhöhen?

_________________
wer andern eine grube gräbt hat ein grubengrabgerät
- oder einfach zu viel zeit
cheve Threadstarter
Hält's aus hier
Beiträge: 5



BeitragVerfasst: Fr 30.09.05 15:41 
auf welche größe z.B.? und wie kann das die geschw. pos. beeinflussen bzw. funktioniert das?


kleine frage am rande: wie kann ich überprüfen ob eine url existiert?
svennissel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22



BeitragVerfasst: Mi 12.10.05 15:10 
Hast du die Debuginformationen fürs Kompilieren abgeschaltet?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mi 12.10.05 15:16 
Moin!

Probier doch das mal:
ausblenden Delphi-Quelltext
1:
const BufferSize = 16384;					

Setzt die Buffergröße auf 16KB.

cu
Narses
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Mi 12.10.05 15:23 
Hallo,

user profile iconcheve hat folgendes geschrieben:
...kleine frage am rande: wie kann ich überprüfen ob eine url existiert?


ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
function CheckUrl(url: string): boolean;
var
  hSession, hfile, hRequest: hInternet;
  dwindex, dwcodelen: dword;
  dwcode: array[1..20of char;
  res: pchar;
begin
  if pos('http://', lowercase(url)) = 0 then
    url := 'http://' + url;
  Result := false;
  hSession := InternetOpen('InetURL:/1.0',
    INTERNET_OPEN_TYPE_PRECONFIG, nilnil0);
  if assigned(hsession) then
  begin
    hfile := InternetOpenUrl(
      hsession,
      pchar(url),
      nil,
      0,
      INTERNET_FLAG_RELOAD,
      0);
    dwIndex := 0;
    dwCodeLen := 10;
    HttpQueryInfo(hfile, HTTP_QUERY_STATUS_CODE,
      @dwcode, dwcodeLen, dwIndex);
    res := pchar(@dwcode);
    result := (res = '200'or (res = '302');
    if assigned(hfile) then
      InternetCloseHandle(hfile);
    InternetCloseHandle(hsession);
  end;

end;

procedure TForm1.CheckURL1Click(Sender: TObject);
begin
  if CheckUrl('http://www.swissdelphicenter.ch/de/tipresult.php'then
    showmessage('Online = http://www.swissdelphicenter.ch/de/tipresult.php')
    else
      showmessage('Adresse existiert nicht oder der Pc ist nicht Online');
end;

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )