Autor Beitrag
DataCool
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 112



BeitragVerfasst: Mo 04.08.03 22:36 
Hi Leute,
mit Threads kenn ich mich einigermaßen aus. Habe hier gerade aber ne Situation, wo ich nicht ganz sicher bin wie's richtig ist.
Problem :
Ich möchte über die IdHttp-Komponente eine Anfrage auf ein PHP-SChript auf meinem Server schicken, in diesem Fall geht es z.B. um eine Anmeldung.
Ich brauche aber auch die Antwort der Http-Anfrage; nach dem Motto :
1 = Anmeldung ok
0 = ???
-1 user oder pwd unbekannt
Damit nicht das ganze Programm solange steht wir die Anfrage ausgeführt wird dachte ich mir, das verlagere das ganze in einen Thread.
D.H. Ich verlagere meine Anfrage in einen Thread warte aber im Hauptprogramm nach der erzeugung solange bis der Thread fertig ist und mir das Ergebnis geliefert hat.
Frage 1:
Ist der GRundgedanke falsch ?
Frage 2:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
Var 
   intTwThd : TInteractiveTWThread; 
   iRes     : Longint; 
begin 
   intTwThd := TInteractiveTWThread.Create({meine login-Parameter}); 
   try 
      // Thread starten 
      intTwThd.Resume; 
      // auf Ende des Threads warten 
      intTwThd.WaitFor; 
      iRes := intTwThd.Result; 
      result := (iRes = 1) or (iRes = 2); 
   finally 
      intTwThd.Terminate; 
   end; 
end;



ist das richtig so ? Weil eigentlich wartet "waitfor" ja solange bis der Thread fertig ist. Der Thread ist auf FreeOnTerminate gestellt und ich greife danach auf die Property Result des Threads zu, obwohl er da ja schon freigegeben sein sollte.
Mit diesem gebastelten Konstrukt geht es, aber ab und zu bekomm ich schutzverletzungen in meiner App es laufen so ca. 6 Thread noch paralellel im Hintergrund. Welcher Thread jetzt wann welchen Fehler bringt kann ich nicht genau sagen, denn das Debugging von dem ganzen ist nicht so einfach, vor allen Dingen, weil mir beim Debuggen der Threads Deplhi mir 50% wahrscheinlichkeit abraucht.
Aber ich glaube Ihr wißt worum es mir geht !

_________________
DataCool
specialwork
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52

Windows XP Professional; Windows Server 2003
Delphi 7 Prof, Delphi 8.Net
BeitragVerfasst: Mo 04.08.03 22:49 
Titel: Asynchroner Zugriff
Hallo DataCool,

Kann man mit der IDHttp-Komponente denn keine asynchronen Zugriffe machen :?:

:arrow: Das würde mich wundern, denn grundlegend sollte doch eigentlich eine Asynchrone Socket verwendet werden.

Gruß, Tom
DataCool Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 112



BeitragVerfasst: Mo 04.08.03 23:49 
weiß jetzt aus dem Stehgreif gar nicht ob das socket syncron bzw. asyncron aufgemacht wird.
Benutze sTmp := Idhttp.get(URL);

_________________
DataCool
specialwork
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52

Windows XP Professional; Windows Server 2003
Delphi 7 Prof, Delphi 8.Net
BeitragVerfasst: Di 05.08.03 23:58 
Hallo DataCool,

Ich bin mir nicht sicher, aber probier mal folgendes was ich aus der Delphi Hilfe entnommen habe:

Zitat:
TIdHTTP.HandleRedirects

Indicates that the client should handle redirects.

ausblenden Delphi-Quelltext
1:
property HandleRedirects: Boolean;					


Description

HandleRedirects is a Boolean property that indicates that the HTTP client should handle redirects in a response from the HTTP server.
When HandleRedirects is False, a redirect in a HTTP response will raise an exception.


in Verbindung mit dem folgendem Event

Zitat:
TIdHTTP.OnRedirect

Specifies the event handler for redirect requests.

ausblenden Delphi-Quelltext
1:
property OnRedirect: TIdHTTPOnRedirectEvent;					


Description

OnRedirect is the TIdHTTPOnRedirectEvent event handler used to respond to redirection requests from an HTTP client.
An Application must assign a procedure to the event handler in order to respond to the event notification.

Gruß, Tom
DataCool Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 112



BeitragVerfasst: Mi 06.08.03 08:49 
@specialwork:
Daran kann es nicht liegen, der PHP-Script den ich aufrufe liegt auf unseren Server und enthält kein redirect, er(der Script) enthält nur ein paar datenbank select und updates und gibt mir bei erfolg ne 1 bzw. ne fehlernummer zurück.

_________________
DataCool