高手帮我看看,这个线程怎么有错啊?

cqwty 2004-11-21 07:54:39
unit commthreadunit;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Sockets;

type
CommThread = class(TThread)
private
{ Private declarations }
FPort:integer;
FTServer:TTcpServer;
RecvStr:TStrings;
procedure AcceptMsg(Sender: TObject;ClientSocket: TCustomIpClient);
protected
procedure Execute; override;
public
constructor create(TS:TTcpServer;Port:integer);
end;


implementation

{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,

Synchronize(UpdateCaption);

and UpdateCaption could look like,

procedure CommThread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }

{ CommThread }

constructor CommThread.create(TS:TTcpServer;Port:integer);
begin
inherited create(false);
FTServer:=TS;
Fport:=Port;
FTServer.LocalPort:=inttostr(FPort);
FreeOnTerminate:=true;
end;
procedure CommThread.AcceptMsg(Sender: TObject;ClientSocket: TCustomIpClient);
var
s: string;
begin
s := ClientSocket.Receiveln;
while s <> '' do
begin
RecvStr.Add(s);
~~~~~~~~~~~~这一句总是有错误
s := ClientSocket.Receiveln;
end;
end;
procedure CommThread.Execute;
begin
{ Place thread code here }
FTServer.OnAccept:=AcceptMsg;
FTServer.Active:=true;
end;

end.
...全文
92 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zeroxing 2004-11-21
  • 打赏
  • 举报
回复
TStrings是一个抽象类,不能够直接创建。
用它的子类。例如:RecvStr := TStringList.Create;就可以了。
cqwty 2004-11-21
  • 打赏
  • 举报
回复
constructor CommThread.create(TS:TTcpServer;Port:integer);
begin
inherited create(false);
FTServer:=TS;
Fport:=Port;
RecvStr := TStrings.Create;
FTServer.LocalPort:=inttostr(FPort);
FreeOnTerminate:=true;
end;
destructor commthread.destory;
begin
RecvStr.Free;
end;
提示的错误abstract error
是怎么回事呢?
longtusoft 2004-11-21
  • 打赏
  • 举报
回复
RecvStr 没有创建!
在Create中必须创建之,在析构中必须FREE之
RecvStr := TStringsList.Create;
cqm2099 2004-11-21
  • 打赏
  • 举报
回复
RecvStr.Add(s);
~~~~~~~~~~~~这一句总是有错误
提示什么错误呀?

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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