Ver Mensaje Individual
  #3  
Antiguo 05-12-2007
wofox wofox is offline
Miembro
 
Registrado: dic 2007
Posts: 28
Reputación: 0
wofox Va por buen camino
Estoy usando Borland Delphi 7, muchas gracias por decirme donde está el chat lo acabo de encontrar.
Espero visitar este foro muy seguido y poco a poco ir aprendiendo.
Gracias por la ayuda pero me gustaría que alguien me explicara el codigo comentándolo, les dejo el código:
Código:
constructor TClientDataThread.Create(CreateSuspended: Boolean);
begin
  inherited Create(CreateSuspended);
  FreeOnTerminate := true;
  ListBuffer := TStringList.Create;
end;

procedure TClientDataThread.Terminate;
begin
  ListBuffer.Free;
  inherited;
end;

procedure TClientDataThread.Execute;
begin
  Synchronize(synchAddDataToControl);
end;

procedure TClientDataThread.synchAddDataToControl;
begin
 TargetList.AddStrings(ListBuffer);
end;
//------------- end TClientDataThread impl -------------------------------------


procedure TForm1.btnActivateServerClick(Sender: TObject);
begin
  TcpServer1.LocalPort := edtLocalPort.Text;
  TcpServer1.Active := True;
end;         

procedure TForm1.btnSendClick(Sender: TObject);
var
  I: Integer;
begin
  TcpClient1.RemoteHost := edtRemoteHost.Text;
  TcpClient1.RemotePort := edtRemotePort.Text;
  try
    if TcpClient1.Connect then
      for I := 0 to memSend.Lines.Count - 1 do
      TcpClient1.Sendln(memSend.Lines[i]);
  finally
    TcpClient1.Disconnect;
  end;
end;

procedure TForm1.TcpServer1Accept(sender: TObject;
  ClientSocket: TCustomIpClient);
var
  s: string;
  DataThread: TClientDataThread;
begin
  // create thread
  DataThread:= TClientDataThread.Create(true);
  // set the TagetList to the gui list that you
  // with to synch with.
  DataThread.TargetList := memRecv.lines;

  // Load the Threads ListBuffer
  DataThread.ListBuffer.Add('*** Connection Accepted ***');
  DataThread.ListBuffer.Add('Remote Host: ' + ClientSocket.LookupHostName(ClientSocket.RemoteHost) +
   ' (' + ClientSocket.RemoteHost + ')');
  DataThread.ListBuffer.Add('===== Begin message =====');
  s := ClientSocket.Receiveln;
  while s <> '' do
  begin
    DataThread.ListBuffer.Add(s);
    s := ClientSocket.Receiveln;
  end;
  DataThread.ListBuffer.Add('===== End of message =====');

  // Call Resume which will execute and synch the
  // ListBuffer with the TargetList
  DataThread.Resume;

end;

Última edición por wofox fecha: 05-12-2007 a las 19:49:40.
Responder Con Cita