当我尝试将端口和主机分配给delphi客户端套接字时,会引发异常“当套接字处于活动状态时无法更改值”。但我没有改变socket.active:= true。任何人都可以提出此错误的可能原因。
procedure CreateSocket(add : pchar);
var
port : integer;
address : string;
host : string;
socket1 : TClientSocket;
begin
setstring(address,add,50);
//showmessage(address) ;
host := split(address,':');
address := del(address,':');
//showmessage(address);
port := strtoint(address);
socket1.port := port; //exception comes here
socket1.host := host;
showmessage('address assigned');
connectionAttempt(Socket1);
CheckDataArrival(socket1);
end;
答案 0 :(得分:1)
如果这是您的实际复制/粘贴代码,那么您已声明TClientSocket
变量但未实例化TClientSocket
对象,因此您将主机和端口设置为无效内存。