N
niuqi31
Unregistered / Unconfirmed
GUEST, unregistred user!
程序中使用了动态创建的Socket,使用起来没有问题。但在程序运行态时释放时却释放不掉。即ClientSocket1!=NULL。很奇怪?求解。
void TForm1::CreateClientSocket(AnsiString HostAddress,int HostPort)
{
ClientSocket1=new TClientSocket(this);
ClientSocket1->Address=HostAddress;
ClientSocket1->Port=HostPort;
ClientSocket1->OnConnect=ClientSocket1Connect;
ClientSocket1->OnDisconnect=ClientSocket1Disconnect;
ClientSocket1->OnRead=ClientSocket1Read;
ClientSocket1->OnError=ClientSocket1Error;
ClientSocket1->Active=true;
}
void TForm1::FreeClientSocket(void) //释放客户端socket
{
ClientSocket1->Active=false;
ClientSocket1->DestroyComponents();
//ClientSocket1=NULL;
}
ClientSocket1 为类的全局指针。
void TForm1::CreateClientSocket(AnsiString HostAddress,int HostPort)
{
ClientSocket1=new TClientSocket(this);
ClientSocket1->Address=HostAddress;
ClientSocket1->Port=HostPort;
ClientSocket1->OnConnect=ClientSocket1Connect;
ClientSocket1->OnDisconnect=ClientSocket1Disconnect;
ClientSocket1->OnRead=ClientSocket1Read;
ClientSocket1->OnError=ClientSocket1Error;
ClientSocket1->Active=true;
}
void TForm1::FreeClientSocket(void) //释放客户端socket
{
ClientSocket1->Active=false;
ClientSocket1->DestroyComponents();
//ClientSocket1=NULL;
}
ClientSocket1 为类的全局指针。