login.cpp//----------------------------------------------
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <main.h>
#include "login.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
Tlogin_on *login_on;
String c_name;
//---------------------------------------------------------------------------
__fastcall Tlogin_on::Tlogin_on(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall Tlogin_on::Button1Click(TObject *Sender)
{
if (Edit1->Text.Length()==0)
{
ShowMessage("您还没有输入妮称!");
}
else
if (Edit1->Text.Length()>0 &&
Edit1->Text.Length()<14)
{
for (int i=Edit1->Text.Length();i<14;i++)
{ Edit1->Text=Edit1->Text+'/20';
c_name=Edit1->Text;
}
mainfrm->Show();
login_on->Visible=false;
}
else
if(Edit1->Text.Length()==14)
{
c_name=Edit1->Text;
}
else
if (Edit1->Text.Length()>14)
{
ShowMessage(" 妮称长度不能超过14!");
Edit1->Text="";
}
}
//---------------------------------------------------------------------------
main.cpp----------------------
下面是FormCreate时的程序
void __fastcall Tmainfrm::FormCreate(TObject *Sender)
{
int i;
String sys;
if (c_name.Length()<14)
{ for (int j=c_name.Length();j<14;j++)
{ c_name=c_name+'/20';
}
}
sys="[系统公告]:欢迎"+c_name+"进入聊天室!";
i=sys.Length();
TMemoryStream *MyStream=new TMemoryStream();
MyStream->Write(&sys[1],i);
NMUDP1->LocalPort=2222;
NMUDP1->RemotePort=2222;
NMUDP1->RemoteHost="210.28.33.255";
NMUDP1->ReportLevel=Status_Basic;
NMUDP1->SendStream(MyStream);
delete MyStream;
NMUDP1->ReportLevel=Status_Trace;
}
//---------------------------------------------------------------------------