📄 unit1.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if (Button1->Caption == "Connect")
{
try
{
ClientSocket->Active = true ;
StatusBar1->SimpleText = "Connecting ..." ;
}
__finally
{
Button1->Caption = "Disconnect" ;
}
}
else
{
ClientSocket->Active = false ;
StatusBar1->SimpleText = "Disconnect" ;
Button1->Caption = "Connect" ;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::txtSendKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if (Key == VK_RETURN)
{
ClientSocket->Socket->SendText(txtSend->Text) ;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ClientSocketConnect(TObject *Sender,
TCustomWinSocket *Socket)
{
StatusBar1->SimpleText = "Connected to: " + Socket->RemoteHost;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ClientSocketConnecting(TObject *Sender,
TCustomWinSocket *Socket)
{
StatusBar1->SimpleText = "Connecting to: " + Socket->RemoteHost;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ClientSocketDisconnect(TObject *Sender,
TCustomWinSocket *Socket)
{
StatusBar1->SimpleText = "Disconnect from: " + Socket->RemoteHost;
Button1->Caption = "Connect" ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ClientSocketError(TObject *Sender,
TCustomWinSocket *Socket, TErrorEvent ErrorEvent, int &ErrorCode)
{
StatusBar1->SimpleText = "Socket Error" ;
Button1->Caption = "Connect" ;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ClientSocketRead(TObject *Sender,
TCustomWinSocket *Socket)
{
txtGet->Text = Socket->ReceiveText() ;
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -