Einzelnen Beitrag anzeigen

Benutzerbild von Flogo
Flogo

Registriert seit: 24. Mär 2003
Ort: Freiburg im Breisgau
317 Beiträge
 
Delphi 7 Professional
 
#1

Allgemeine Frage zu synchroize() in Threads

  Alt 13. Jan 2004, 19:46
Ich hab folgendes versucht:
Delphi-Quellcode:
procedure Thread.Execute;
begin
  { Place thread code here }
  repeat
    Application.ProcessMessages;
  until terminated;
end;

function Thread.WalkTo(APoint: TPoint): Boolean;
begin
  WalkToPoint := APoint;
  synchronize(Ziel);
  result := false;
  repeat
    if (Form1.An.Ziel.X <> APoint.X) or (Form1.An.Ziel.Y <> APoint.Y) then exit;
    Application.ProcessMessages;
  until (Form1.An.Left = APoint.X) and (Form1.An.Top = APoint.Y);
  result := true;
end;

procedure Level.Ziel;
begin
  Form1.Ziel(WalkToPoint); // Setzt Form1.An.Ziel auf WalkToPoint
end;
Bei dem Synchronize bleibt er aber immer hängen. (Die Proc Ziel wird nie ausgeführt). Was mache ich falsch? muss die synchronize Methode irgendwelche Vorraussetzungen erfüllen? (z.B. mit genau dem gleichen Namen im HauptThread deklariert sein)
Komischerweise wird das Ziel richtig gesetzt wenn man statt synchronize(ziel);   Form1.Ziel(WalkToPoint); direkt anspricht. Also wozu braucht man das Synchronize überhaupt?
If one coincidence can occur, then another coincidence can occur. And if one coincidence happens to occur just after another coincidence, then that is just a coincidence.
DNA

www.Anyxist.de
  Mit Zitat antworten Zitat