|
쓰레드를 추가하고 다음과 같이 구성했습니다
#pragma package(smart_init)
//---------------------------------------------------------------------------
// Important: Methods and properties of objects in VCL can only be
// used in a method called using Synchronize, for example:
//
// Synchronize(UpdateCaption);
//
// where UpdateCaption could look like:
//
// void __fastcall TCP::UpdateCaption()
// {
// Form1->Caption = "Updated in a thread";
// }
//---------------------------------------------------------------------------
__fastcall TCP::TCP(void)
: TThread(false)
{
this->FreeOnTerminate = false;
TClientSocket *Client = NULL;
Client = new TClientSocket(NULL);
Priority = tpTimeCritical;
}
//---------------------------------------------------------------------------
void __fastcall TCP::Execute()
{
//---- Place thread code here ----
while(!Terminated)
{
}
}
//---------------------------------------------------------------------------
void __fastcall TCP::fn_SockOpen()
{
Client->Host = "192.168.0.142";
Client->Port = 5001;
if(!Client->Socket->Connected)
{
Client->Open();
}
}
//---------------------------------------------------------------------------
void __fastcall TCP::fn_SockClose()
{
if(Client->Socket->Connected)
{
Client->Close();
}
}
//---------------------------------------------------------------------------
void __fastcall TCP::fn_SockSend(BYTE *SendByte, int size)
{
if(Client->Socket->Connected)
{
Client->Socket->SendBuf(SendByte,size);
}
}
__fastcall TCP::~TCP()
{
delete Client;
}
메인 폼에서 b = new TCP; 이렇게 하고
b->fn_SockOpen(); 이코드를 통해 서버에 연결 하려고 했습니다.
프로그램 실행해보면 오픈에서
Client->Host = "192.168.0.142";
이부분에서 에러가 생기면서 프로그램이 죽네요
왜 도대체 저 코드라인을 가르치면서 죽는지 모르겠습니다.
첨부 파일은 코드가드가 내뿜은 메세지 입니다
테스트환경은 윈7에 빌더6.0 입니다
|