Alla fine ci sono arrivato!!!
codice:
function SeekFreePort(start : integer) : integer;
var
i : Integer;
TestSocket : TIdSimpleServer;
begin
TestSocket := TIdSimpleServer.Create(nil);
for i := start to 65535-1 do
begin
try
TestSocket.BoundPort := i;
TestSocket.BoundIP := '127.0.0.1';
TestSocket.CreateBinding;
TestSocket.BeginListen;
except
TestSocket.EndListen;
Continue;
end;
Break;
end;
Result := i;
TestSocket.Free;
end;
L'ho fatta io ispirandomi a una vecchia funzione che utilizzava ancora la vecchia classe TServerSocket. Diciamo che ho fatto un porting...
Speriamo serva a qualcun altro!
P.S.: credo siano necessari i componenti Indy 10 per utilizzare quella funzione.
A presto