SocketConnection.BeforeDisconnect:=Addr(SocketConnectionBeforeDisconnect);
SocketConnection.BeforeDisconnect:=TNotifyEvent(SocketConnectionBeforeDisconnect);
都出错,我很弱的

解决方案 »

  1.   

    用SocketConnection.BeforeDisconnect:=@(SocketConnectionBeforeDisconnect);
    试试。
      

  2.   

    也可以在SocketConnection.BeforeDisconnect 调用SocketConnectionBeforeDisconnect
    效果一样的。
      

  3.   

    ScoketConnection.OnBeforeDisconnect:=SocketConnectionBeforeDisconnect;
    我没有试,不过应该行
      

  4.   

    skimwater(掠水惊鸿):
    我的SocketConnection是在运行中产生的,只能动态赋予事件
      

  5.   

    TSocketConnection根本没有OnBeforeDisconnect这个定义的,只有TSocketConnection.BeforeDisconnect:TNotifyEvent,由于必须在运行中创建,只能动态赋予事件函数,我试过了,SocketConnection.BeforeDisconnect:=@(SocketConnectionBeforeDisconnect);也不行的  
    :~~(
      

  6.   

    怎么会不行。
    type
      TForm1 = class(TForm)
      ...
      private
        procedure SocketBeforeConnection(Sender: Tobject);
      ...
      end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      SocketConnection1.BeforeConnect :=SocketBeforeConnection ;
    end;procedure TForm1.SocketBeforeConnection(Sender: Tobject);
    begin
      Showmessage('begin Connectioning... Destory this dialog.');
    end;
      

  7.   

    确实是报错啊,Incompatible types: method pointer and regular procedure :(
    我的源代码:unit xxx;
    interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      Menus, registry, ScktComp,Db, DBClient, MConnect, SConnect;var
     SocketConnection:TSocketConnection;function ClientInit():integer;
    procedure SocketConnectionBeforeDisconnect(Sender: TObject);implementationfunction ClientInit():integer;
    begin
    SocketConnection:=TSocketConnection.Create(nil);
    SocketConnection.Address:='127.0.0.1';
    SocketConnection.Port:=211;
    SocketConnection.ServerName:='pServer.RDMain';
    SocketConnection.BeforeDisconnect:=SocketConnectionBeforeDisconnect;   //这里出错
    SocketConnection.Open;
    end;procedure SocketConnectionBeforeDisconnect(Sender: TObject);
    begin
    ShowMessage('disconnect');
    end;
      

  8.   

    你把那些定义对象和那些事件放在当前类中的私有部分中试试。
    type
      TForm1=class(tform)
      ...
      private
        scSocketConnection: TSocketConnection;
        procedure SocketBeforeDisConnection(Sender: TObject);
      end;
    有些不知什么原因,如果你定义的过程或函数是全局的话,像你那样,就会出错,莫名其妙,
    不过你把那些定义放在那应该不会错。
      

  9.   

    谢谢,我把对象和事件都放到一个自定类中,问题解决了,但又有了问题,SocketConnection在服务器断开后会报错,然后引发BeforeDisconnection事件,很是难看,该如何解决呢?