5,386
社区成员
发帖
与我相关
我的任务
分享
type
TProcessCom =class(TThread)
private
sSocket:TCustomWinSocket;
lstItem:TListItem;
sComm:Byte;
sString:AnsiString;
pStrList, pStrList2:TStringList;
SocketData: TSocketData;
protected
procedure Execute; override;
procedure DOSynJob;
Public
constructor Create(FSocket:TCustomWinsocket;FComm:Byte;FString:AnsiString);
destructor Destroy; override;
end;
implementation
uses UnitMain;
constructor TProcessCom.Create(FSocket:TCustomWinsocket;FComm:Byte;FString:AnsiString);
begin
inherited Create(False);
sSocket:=FSocket;
sComm:=FComm;
sString:=FString;
FreeOnTerminate:=True;
Suspended:=False;
end;
destructor TProcessCom.Destroy;
begin
inherited Destroy;
end;
Function Explode(sDelimiter: string; sSource: String): TStringList;
Var
c: Word;
Begin
Result := TStringList.Create;
C := 0;
While sSource <> '' Do
Begin
If Pos(sDelimiter, sSource) > 0 Then
Begin
Result.Add(Copy(sSource, 1, Pos(sDelimiter, sSource) - 1 ));
Delete(sSource, 1, Length(Result[c]) + Length(sDelimiter));
End
Else
Begin
Result.Add(sSource);
sSource := ''
End;
Inc(c);
End;
End;
procedure TProcessCom.Execute;
var
lstTemp:TListItem;
begin
if sSocket.Data = nil then begin
SocketData := TSocketData.Create;
sSocket.Data := SocketData;
end;
case sComm of
PACK_AUTH:
begin
pStrList := Explode('|',sString);
if pStrList.Count <> 7 then begin
FormMain.DisconnectSocket(sSocket);
exit;
end else begin
Synchronize(dosynJob);
end;
end;
end;
if pStrList<>nil then pStrList.Free;
end;
procedure TProcessCom.DOSynJob;
var
IpAddr:AnsiString;
begin
IpAddr:=GetIPtoAdder(sSocket.RemoteAddress);
lstItem:=FrameOnlineServer.OnlineLV.Items.Add;// 访问VCL就出错
lstItem.Caption:=sSocket.RemoteAddress;
lstItem.SubItems.Add(string(IpAddr));
lstItem.SubItems.Add(pStrList[1]);
lstItem.SubItems.Add(pStrList[8]);
lstItem.SubItems.Add(pStrList[2]);
lstItem.SubItems.Add(pStrList[3]);
lstItem.SubItems.Add(pStrList[4]);
lstItem.SubItems.Add(pStrList[0]);
lstItem.SubItems.Add('test');
lstItem.SubItemImages[2]:=GetFlag(pStrList[8]);
lstItem.SubItems.Objects[0]:=sSocket;
lstItem.ImageIndex:=143;
lstItem.OverlayIndex:=137;
AddLog('添加主机成功: ' + sSocket.RemoteAddress,clBlue);
TSocketData(sSocket.Data).lstConnectionItem := lstitem;
TSocketData(sSocket.Data).sUserPath := pStrList.Strings[1];
TSocketData(sSocket.Data).sRemoteHost := sSocket.RemoteAddress;
CountConnections;
end;
end.
IpAddr:=GetIPtoAdder(sSocket.RemoteAddress);
FormMain.Caption:='test';//这里并没有出错
lstItem:=FrameOnlineServer.OnlineLV.Items.Add; //这里访问就出错了