Ver Mensaje Individual
  #5  
Antiguo 16-12-2015
josepicd josepicd is offline
Miembro
 
Registrado: jun 2015
Posts: 57
Reputación: 12
josepicd Va por buen camino
Os pongo este codigo, me funciona bien pero creo que tengo algun problema con la liberacion de los hilos, porque lo ejecuto una primera vez y ok, la segunda vez que le doy, a veces funciona, a veces se para por la mitad y le lanza el error que adjunto. Supongo que se queda corto de recursos porque no libero algo bien.

Código Delphi [-]
constructor TSearchPLCs.Create( sip : string; lst : TStrings);
  begin
    inherited create( true);
    FreeOnTerminate := true;

    faddress := sip;
    self.lst := lst;

    fcs := TClientSocket.Create( nil);
    fcs.ClientType := ctNonBlocking;
    fcs.Port       := 7000;
    fcs.Address    := faddress;
    resume;
  end;

Destructor TSearchPLCs.Destroy;
begin
  if fcs.Active then fcs.close;
  fcs.Free;
  inherited;
end;


procedure TSearchPLCs.Execute;
  begin
    try
      fcs.Open; delay( 150);
    except
    end;
    if fcs.Active then Synchronize( dosync);
    terminate;
  end;

procedure TSearchPLCs.DoSync;
begin
  lst.Add( faddress);
end;

//////////////////////////////////////////

procedure TForm1.Button1Click(Sender: TObject);
const base = '192.168.0.';
var
  i: Integer; list : TStrings;
begin
  lsb.Items.Clear;
  list := TStringList.Create;

  for I := $01 to $FF do
  begin
    TSearchPLCs.Create(base + inttostr(i), list);
    caption := base + inttostr(i);
  end;

  lsb.Items.Assign( list);
  list.Free;
end;
Imágenes Adjuntas
Tipo de Archivo: jpg error.JPG (29,0 KB, 5 visitas)
Responder Con Cita