Ich habe eine Klasse TPoll abgeleitet von TThread geschrieben, die eine eigene WaitforResult-Methode hat. Im Main-Loop wird initialisiert, eine Nachricht ins Netzwerk verschickt und auf diese Methode gewartet. Das klappt ausgezeichnet, bis auf den Fall, dass ich von einem Timer gesteuert die Routine aufrufe. Während der Timer tickt, läuft alles bestens. Nur dann, wenn der Timer die "OutOfTime"-Methode aufruft, kommt gar nichts mehr durch. Leider muss ich wohl einiges an Code posten

Code: Alles auswählen
procedure TPoll.SynchMethod;
begin
Application.ProcessMessages;
end;
procedure TPoll.WaitforResult;
begin
while not Done and not Application.Terminated do
begin
Sleep(100);
Synchronize(@SynchMethod);
end;
if assigned(aForm) and aForm.Visible then aForm.Hide; //aForm ist zur Rückmeldung da.
end;
procedure TPoll.SetAnswer(aSender: string; const aValue: boolean);
var i:integer;
begin
for i:=0 to NumberOfPlayers-1 do
if PlayerName(i)=aSender then
begin
case aValue of
true : FPollState[i]:=plYes;
false : FPollState[i]:=plNo;
end;
if assigned(aForm) and (aForm.Visible) then
case aValue of
true : aImage[i].Picture.Bitmap.LoadFromLazarusResource('plYes');
false : aImage[i].Picture.Bitmap.LoadFromLazarusResource('plNo');
end;
break;
end;
aButton.Enabled:=true;
FPollResult:=true;
for i:=0 to NumberOfPlayers-1 do
begin
aButton.Enabled:=aButton.Enabled and (FPollState[i]<>plWait);
FPollResult:=FPollResult and (FPollState[i]=plYes);
end;
if aButton.Enabled and (not aForm.Visible or aCheckBox.Checked) then
DoButtonClick(self);
end;
procedure TPoll.DoButtonClick(Sender: TObject);
begin
done:=true;
end;
Code: Alles auswählen
procedure TThreadTimer.Execute;
var z:Longword;
begin
while not Terminated do
begin
if (FTimeLeft=0) then Suspend;
Sleep(1000);
if (FTimeLeft>0) and not Terminated then
begin
z:=(GetTickCount-FStart) div 1000;
if FInterval>z then FTimeLeft:=FInterval-z else FTimeLeft:=0;
Synchronize(@SyncMethod);
end;
end;
end;
procedure TThreadTimer.SyncMethod;
begin
if assigned(FOnTimerTick) then FOnTimerTick(FTimeLeft);
if (FTimeLeft=0) and assigned(FOnTimer) then FOnTimer(self);
end;
Code: Alles auswählen
procedure TfmMain.DoTimer(Sender: TObject);
begin
acNextPlayerExecute(self);
end;
procedure TfmMain.acNextPlayerExecute(Sender: TObject);
...
Poll.Initialize(false);//false -> aForm.Visible=false
TCPClient.Send(nwCheckWord,TCPClient.Name,bRec[fmNetwork.IsGameServer],sl[i]); //Nachricht ins Netzwerk
Poll.WaitforResult;
if not Poll.Result then...
...
Hat jemand eine Idee?