Autor Beitrag
LonghornUser
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 796



BeitragVerfasst: Mo 22.12.03 20:43 
Hallo,

Ich habe mal eine Frage:

Wie kann ich testen, ob eine Datei, auf die ich mit einer URL zeige, existiert ? Also in etwa so:

If DateiExistiert('http://www.hallo.com/hallo.zip') then showmessage('Ja') else showmessage('Nein');

Da dachte ich mir doch, dass man einfach DateiExistiert durch FileExists ersetzt. Leider gab die Zeile immer 'Nein' aus, weil die funktion fileexists nur für lokale Systeme funktioniert.

Wie aber mache ich es im Internet ?

Ich hoffe auf Antworten.

ciao
DeCodeGuru
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1333
Erhaltene Danke: 1

Arch Linux
Eclipse
BeitragVerfasst: Mo 22.12.03 21:15 
Ich habe mal folgenden Code auf meiner HDD gefunden. Keine Ahnung, ob der funtzt, aber er müsste eigentlich alles machen, was du brauchst.

ausblenden 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:
function CheckAvailability(URL: String): Boolean;
var
  Session, thefile: hInternet;
  index,CodeLength: cardinal;
  Code: array[1..20] of Char;
  res: PChar;
begin
  Result := False;
  Session := InternetOpen('InetURL:/1.0',INTERNET_OPEN_TYPE_PRECONFIG,nil,nil,0);
  if Assigned(session) then
  begin
    thefile := InternetOpenUrl(session, pchar(URL), nil, 0, INTERNET_FLAG_RELOAD,0);
    Index := 0;
    CodeLength := 10;
    HttpQueryInfo(thefile, HTTP_QUERY_STATUS_CODE, @Code, CodeLength, Index);
    res:= pchar(@Code);
    if res = '200' then
      Result := True;

    if Assigned(thefile) then
      InternetCloseHandle(thefile);
  end;
  InternetCloseHandle(session);
end;


Achja, du müsstest die Unit WinINET einbinden. Kannst es ja mal testen :wink:

_________________
Viele Grüße
Jakob
LonghornUser Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 796



BeitragVerfasst: Mo 22.12.03 22:07 
Danke. Das funktioniert wunderbar.

Aber leider reagiert meine anwendung dann für ~4 sek. nicht. Ich kenne den Befehl application.ProcessMessages;, weiß aber nicht, wie man ihn einsetzen könnte. So geht es jedenfalls nicht:
ausblenden Delphi-Quelltext
1:
2:
3:
application.ProcessMessages;
if CheckAvailability('http://www.hallo.de/hallo.zip')=true then begin
showmessage('Ja') end else showmessage('Nein');


Aber wie dann ?

Moderiert von user profile iconPeter Lustig: Code- durch Delphi-Tags ersetzt
DeCodeGuru
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1333
Erhaltene Danke: 1

Arch Linux
Eclipse
BeitragVerfasst: Mo 22.12.03 22:41 
Habe gerade mal nachgesehen. Ich hatte die Funktion in ner ähnlichen Form in nen Thread. Das kannste probieren. :)

_________________
Viele Grüße
Jakob
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Di 23.12.03 13:13 
oder nimm doch die indy komponenten mit der anitifreeze kompo. dann musst du aber den code selber entwickeln.

_________________
In the beginning was the word.
And the word was content-type: text/plain.
DeCodeGuru
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1333
Erhaltene Danke: 1

Arch Linux
Eclipse
BeitragVerfasst: Di 23.12.03 13:33 
Man kann auch für jeden Sch*** die Indys zücken :wink: :mrgreen:

_________________
Viele Grüße
Jakob
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Di 23.12.03 13:59 
klar. da haste einfach den vollen komfort

_________________
In the beginning was the word.
And the word was content-type: text/plain.