我想在一个独立的单元中使用此控件,可是在没有Form的情况下它的create方法不能使用参数self,如何解决?

解决方案 »

  1.   

    那他的事件怎么声明?
    方到uses的下面不行呀!
      

  2.   

    with TClientSocket.Create(nil) do
    try
    finally
      Free;
    end;
      

  3.   

    自己可以写一些事件,并把TClientSocket的事件赋给它,即可。
    即自己对TClientSocket进行再封装
      

  4.   

    自定义事件处理方法
    procedure myCltOnConnect(param1,...) ;  参数要和控件的参数一致cltSocket1:=TClientSocket.Create(nil)
    cltSocket1.onConnect:=myCltOnConnect;
      

  5.   

    我这样做了,可是他提时说:method Pointer and regular procedure
    怎么回事?
      

  6.   

    比较简单的方法,你先在一个form中,放一个你 TClientSocket, 点击 生成相应的事件,再将生成的事件copy到你的 unit中, 去掉前面那些 TForm1.
    直接用事件就可,然后,
    cltSocket1.onConnect := CltOnConnect;
    可设定对应事件!
    你有两个create选择cltSocket1:=TClientSocket.Create(nil)
    or
    cltSocket1:=TClientSocket.Create(application)但一般用前一种比较好!我觉得!
      

  7.   


    这个方法可以使用.不过要注意这个过程的声明
    首先声明一个类:
    TMyClient = class(TClientSocket)
      public
        procedure onConnect(你的参数);
       .
       .
       .
       .
      end;procedure myCltOnConnect(param1,...) ; 之后再调用:cltSocket1:=TMyClient .Create(nil)
    TMyClient .onConnect:=myCltOnConnect;这样就可以了.
      

  8.   

    我的onConnect中的参数和myCltOnConnect钟的参数一样
    可他的提示是没有足够的实际参数:(
    还有,还说什么onConnect不安全之类的:(
      

  9.   

    cltSocket1:=TClientSocket.Create(nil)
    cltSocket1.onConnect:=myCltOnConnect; // 这一句不要带参数。只写方法名
      

  10.   

    uses forms;  cltSocket1:=TClientSocket.Create(Application)
      

  11.   

    我在付值的时候没有些参数呀!
    我的程序如下:大家给看一下使那里的错:
    ses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, Sockets, StdCtrls,ScktComp, ExtCtrls,strUtils;
       procedure ClientRead(Sender:TObject;Socket:TCustomWinSocket);
       procedure ClientDisconnect(Sender:TObject;Socket:TCustomWinSocket);
       procedure ClientConnect(Sender:TObject;Socket:TCustomWinSocket);
       procedure ClientError(Sender:TObject;Socket:TCustomWinSocket;
               ErrorEvent:TErrorEvent;var ErrorCode:Integer);
      //////////////////////////////////////////////////////
           Function connect(stAd:string;iPor:integer):Boolean;
          procedure DisConnect();
          Function  SendText(stParm:string):Boolean;
           procedure DoIt(stInfor:string);var
      isConnecting,isConnected,isDisConnect:Boolean;
       keyEnd:string; //保存最终密钥
       Client_Encry:TClientSocket;implementation Function connect(stAd:string;iPor:integer):Boolean;
     begin
      Client_Encry:=TClientSocket.Create(nil);
      Client_Encry.Host:=stAd;
      Client_Encry.Port:=iPor;//声明事件  Client_Encry.OnDisconnect:=ClientDisconnect;
      Client_Encry.OnRead:=ClientRead;
      Client_Encry.OnError:=ClientError;
      Client_Encry.OnConnect:=ClientConnect;
      //设置连接
      Client_Encry.Active:=True;
      isConnecting:=True;
      Result:=isConnecting;
     end;
      

  12.   

    .....
      Client_Encry.OnRead:=ClientRead;//这儿的ClientRead类型因为是一个对象的成员函数..
    ..
    你定义的
       procedure ClientRead(Sender:TObject;Socket:TCustomWinSocket);
    是独立的函数,而非成员函数.
      

  13.   

    TMyClient=class(TComponent)
      constructor Create(AOwner:TComponent);override;
      destructor Destroy;override;
      ClientSocket:TClientSocket;
      procedure OnConnect(Sendet:TObject);
    end;constructor TMyClient.Create(AOwner:TComponent);
    begin
      inherited;
      ClientSocket:=TClientSocket.Create(self);
      ClientSocket.OnConnect:=OnConnect;
    end;
    destructor TMyClient.Destroy;
    begin
      ClientSocket.Free;
      inherited;
    end;
    procedure TMyClient.OnConnect(Sender:TObject);
    beginend;