关于TClientSocket问题

liunini 2003-09-29 03:01:04
我想在一个独立的单元中使用此控件,可是在没有Form的情况下它的create方法不能使用参数self,如何解决?
...全文
152 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
hiflower 2003-09-30
  • 打赏
  • 举报
回复
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);
begin

end;
halfdream 2003-09-29
  • 打赏
  • 举报
回复
.....
Client_Encry.OnRead:=ClientRead;//这儿的ClientRead类型因为是一个对象的成员函数..
..
你定义的
procedure ClientRead(Sender:TObject;Socket:TCustomWinSocket);
是独立的函数,而非成员函数.

liunini 2003-09-29
  • 打赏
  • 举报
回复
我在付值的时候没有些参数呀!
我的程序如下:大家给看一下使那里的错:
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;
huojiehai 2003-09-29
  • 打赏
  • 举报
回复
uses forms;

cltSocket1:=TClientSocket.Create(Application)
WQmeng 2003-09-29
  • 打赏
  • 举报
回复
cltSocket1:=TClientSocket.Create(nil)
cltSocket1.onConnect:=myCltOnConnect; // 这一句不要带参数。只写方法名
liunini 2003-09-29
  • 打赏
  • 举报
回复
我的onConnect中的参数和myCltOnConnect钟的参数一样
可他的提示是没有足够的实际参数:(
还有,还说什么onConnect不安全之类的:(
甜而不腻 2003-09-29
  • 打赏
  • 举报
回复

这个方法可以使用.不过要注意这个过程的声明
首先声明一个类:
TMyClient = class(TClientSocket)
public
procedure onConnect(你的参数);
   .
   .
   .
   .
end;

procedure myCltOnConnect(param1,...) ;

之后再调用:

cltSocket1:=TMyClient .Create(nil)
TMyClient .onConnect:=myCltOnConnect;

这样就可以了.
aiirii 2003-09-29
  • 打赏
  • 举报
回复
比较简单的方法,你先在一个form中,放一个你 TClientSocket, 点击 生成相应的事件,再将生成的事件copy到你的 unit中, 去掉前面那些 TForm1.
直接用事件就可,然后,
cltSocket1.onConnect := CltOnConnect;
可设定对应事件!
你有两个create选择

cltSocket1:=TClientSocket.Create(nil)
or
cltSocket1:=TClientSocket.Create(application)

但一般用前一种比较好!我觉得!
liunini 2003-09-29
  • 打赏
  • 举报
回复
我这样做了,可是他提时说:method Pointer and regular procedure
怎么回事?
WQmeng 2003-09-29
  • 打赏
  • 举报
回复
自定义事件处理方法
procedure myCltOnConnect(param1,...) ; 参数要和控件的参数一致

cltSocket1:=TClientSocket.Create(nil)
cltSocket1.onConnect:=myCltOnConnect;
songcallray 2003-09-29
  • 打赏
  • 举报
回复
自己可以写一些事件,并把TClientSocket的事件赋给它,即可。
即自己对TClientSocket进行再封装
zhoutian618 2003-09-29
  • 打赏
  • 举报
回复
with TClientSocket.Create(nil) do
try
finally
Free;
end;
songcallray 2003-09-29
  • 打赏
  • 举报
回复
能说一下想用它干什么,想怎么操作它?
songcallray 2003-09-29
  • 打赏
  • 举报
回复
能说一下想用它干什么,想怎么操作它?
liunini 2003-09-29
  • 打赏
  • 举报
回复
那他的事件怎么声明?
方到uses的下面不行呀!
WQmeng 2003-09-29
  • 打赏
  • 举报
回复
create(nil)
liunini 2003-09-29
  • 打赏
  • 举报
回复
能不能实现这种功能,可不可以应一声呀!!!!!!
liunini 2003-09-29
  • 打赏
  • 举报
回复
没有人来回答我的问题,为什么?
是太简单不愿意回答吗?

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧