?? unit1.~cpp
字號:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
int g_ConnectState=0;//連接狀態
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void TForm1::SetConnectBtnState()
{
//TODO: Add your source code here
switch(g_ConnectState)
{
case 0:
Button1->Caption="連接";
Button1->Enabled=TRUE;
break;
case 1:
Button1->Caption="斷開";
Button1->Enabled=TRUE;
break;
case 2:
Button1->Enabled=FALSE;
break;
}
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(g_ConnectState==0)
{
ClientSocket1->Address=Edit1->Text;
ClientSocket1->Port=atoi(Edit2->Text.c_str());
ClientSocket1->Open();
g_ConnectState=2;
SetConnectBtnState();
}
else
{
ClientSocket1->Close();
g_ConnectState=0;
SetConnectBtnState();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnConnect(TObject *Sender,
TCustomWinSocket *Socket)
{
g_ConnectState=1;
SetConnectBtnState();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnDisConnect(TObject *Sender,
TCustomWinSocket *Socket)
{
g_ConnectState=0;
ClientSocket1->Close();
SetConnectBtnState();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnRead(TObject *Sender, TCustomWinSocket *Socket)
{
Edit4->Text+=ClientSocket1->Socket->ReceiveText();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
ClientSocket1->Socket->SendText(Edit3->Text);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnError(TObject *Sender, TCustomWinSocket *Socket,
TErrorEvent ErrorEvent, int &ErrorCode)
{
g_ConnectState=0;
ClientSocket1->Close();
SetConnectBtnState();
ErrorCode=0;
}
//---------------------------------------------------------------------------
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -