C
cqwty
Unregistered / Unconfirmed
GUEST, unregistred user!
我想把tcpclient控件使用在多线程里面,可是出错,不能建立起来,请看下面代码!
unit ConnThreadUnit;
interface
uses
Classes, Sockets, ExtCtrls, SysUtils;
type
ConnThread = class(TThread)
private
{ Private declarations }
FTimer:TTimer;
FIPList:TStrings;
FTcpClient:TTcpClient;
procedure ontime(Sender: TObject);
procedure addinfo;
protected
procedure Execute; override;
destructor Destroy; override;
public
constructor create(IPAddress:Tstrings);
end;
implementation
{ ConnThread }
constructor ConnThread.create(IPAddress:Tstrings);
begin
FTcpClient:=TTcpClient.Create(nil);//出错,内存访问错误
如果这一句换成
FTcpClient:=TTcpClient.Create(self);
错误提示就成了tcomponent和thread类不匹配
如果换成如下:
FTcpClient:=TTcpClient.Create();
提示必须填写参数
FTcpClient.RemotePort:='5001';
FTcpClient.Active:=false;
FTimer:=TTimer.Create(nil);
FTimer.Enabled:=false;
FTimer.Interval:=600;//10minutes
FIPList:=TStringlist.Create;
FIPList:=IPAddress;
inherited create(false);
end;
destructor ConnThread.Destroy;
begin
//
end;
procedure ConnThread.addinfo;
begin
////
end;
procedure ConnThread.ontime(sender:TObject);
begin
//
end;
procedure ConnThread.Execute;
begin
//
end;
end.
unit ConnThreadUnit;
interface
uses
Classes, Sockets, ExtCtrls, SysUtils;
type
ConnThread = class(TThread)
private
{ Private declarations }
FTimer:TTimer;
FIPList:TStrings;
FTcpClient:TTcpClient;
procedure ontime(Sender: TObject);
procedure addinfo;
protected
procedure Execute; override;
destructor Destroy; override;
public
constructor create(IPAddress:Tstrings);
end;
implementation
{ ConnThread }
constructor ConnThread.create(IPAddress:Tstrings);
begin
FTcpClient:=TTcpClient.Create(nil);//出错,内存访问错误
如果这一句换成
FTcpClient:=TTcpClient.Create(self);
错误提示就成了tcomponent和thread类不匹配
如果换成如下:
FTcpClient:=TTcpClient.Create();
提示必须填写参数
FTcpClient.RemotePort:='5001';
FTcpClient.Active:=false;
FTimer:=TTimer.Create(nil);
FTimer.Enabled:=false;
FTimer.Interval:=600;//10minutes
FIPList:=TStringlist.Create;
FIPList:=IPAddress;
inherited create(false);
end;
destructor ConnThread.Destroy;
begin
//
end;
procedure ConnThread.addinfo;
begin
////
end;
procedure ConnThread.ontime(sender:TObject);
begin
//
end;
procedure ConnThread.Execute;
begin
//
end;
end.