Ver Mensaje Individual
  #5  
Antiguo 10-07-2015
Avatar de gatosoft
[gatosoft] gatosoft is offline
Miembro Premium
 
Registrado: may 2003
Ubicación: Bogotá, Colombia
Posts: 833
Reputación: 22
gatosoft Va camino a la fama
Apoyando lo que dice Neftalí,

en el procedimeinto createsrv son "sospechosas" las asignaciones:

Código Delphi [-]
srv.OnClientConnect    :=  doconnect;
srv.OnClientDisconnect := dodisconnect;

debido a que los evbentos normalemente deben pertenecer a un objeto y no puedens er procedimientos aislados. Ver la definición del evento TNotifyEvent:

Código Delphi [-]
TNotifyEvent = procedure (Sender:TObject) of Object;

Por tanto, deberias definir tus procedimientos en una clase... como buena práctica ademas..

Respondiendo tu pregunta específica, tal como dicen ElKurgan y AgustinOrtu , puedes definir tus propios eventos en lugar de utilizar el timer, asi:


Código Delphi [-]
Unit Srv;

interfase

Type

TConexion=Clas(TObject)
Private
  FOnClientConnect: TNotifyEvent;
  FOnClientDisConnect: TNotifyEvent;
Public  
  Property OnClientConnect: TNotifyevent read FOnClientConnect write FOnClientConnect;
  Property OnClientDisconnect: TNotifyevent read FOnClientDisconnect write FOnClientDisconnect;
  procedure createsrv;
  procedure doconnect;
  procedure dodisconnect;
End;//TConexion

implementation

procedure TConexion.createsrv;
begin
  srv := TServerSocket.Create( nil);
  srv.Port := 1000;
  srv.Active := true;
  srv.OnClientConnect    :=  doconnect;
  srv.OnClientDisconnect := dodisconnect;
end;

procedure TConexion.doconnect;
begin
  lconnect := true;
  if Assigned(FOnClientConnect) then
     OnClientConnect(nil);
end;

procedure TConexion.dodisconnect;
begin
  lconnect := false;
  if Assigned(FOnClientDisConnect) then
     OnClientDisConnect(nil);  
end;

end.

en tu form principal haces:


Código Delphi [-]
Unit TForm

TFrom1 = Clas(TForm)
Public
  LaConexion: TConexion;
  procedure MyOnClientConnect(Sender:TObject);
  procedure MyOnClientDisConnect(Sender:TObject);
end;

// Al crear el form abrimos la conexion
FormCreate:
Begin
 .....
  LaConexion:= TConexion.create;
  LaConexion.OnClientConect:= MyOnClientConnect;
  LaConexion.OnClientDisconect:= MyOnClientDisConnect;
  LaConexion.createsrv;
 ..... 
End;

Formclose:
Begin
  LaConexion.Free;
end;

procedure MyOnClientConnect(Sender:TObject);
Begin
  label1.caption := 'conectado'
end;

procedure MyOnClientDisConnect(Sender:TObject);
Begin
  label1.caption := 'desconectado';
end;

Saludo,
Responder Con Cita