Folgender Code geht (zumindest bei mir) wunderbar.
(Testified under Delphi 7)
Delphi-Quellcode:
procedure Delay(Milliseconds: Integer);
var
Tick: DWord;
Event: THandle;
begin
Event := CreateEvent(nil, False, False, nil);
try
Tick := GetTickCount + DWord(Milliseconds);
while (Milliseconds > 0) and
(MsgWaitForMultipleObjects(1, Event, False, Milliseconds, QS_ALLINPUT) <> WAIT_TIMEOUT) do
begin
Application.ProcessMessages;
Milliseconds := Tick - GetTickcount;
end;
finally
CloseHandle(Event);
end;
end;
function mysql_check(target : string) : boolean;
var
zSocket: TClientSocket;
begin
zSocket := TClientSocket.Create(nil);
zSocket.Port:=3306;
zSocket.Host:=target;
zSocket.Open;
Delay (1000);
result:=zSocket.Active;
if zSocket.Active then zSocket.Close;
zSocket.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if mysql_check('127.0.0.1) then Beep;
end;