delphi socket异常不能改变主机和端口的值

时间:2014-02-26 03:53:18

标签: sockets delphi-7

当我尝试将端口和主机分配给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;

1 个答案:

答案 0 :(得分:1)

如果这是您的实际复制/粘贴代码,那么您已声明TClientSocket变量但未实例化TClientSocket对象,因此您将主机和端口设置为无效内存。