⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainform.~cpp

📁 自动聊天机器人
💻 ~CPP
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "mainform.h"
#include "Robot.h"
#include "About.h"
#include "Approbot.h"
#include "Robotconfig.h"
#include "RobotHelp.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)                         // 在程序刚开始时所做的工作
{
    this->mp_Interface = new TFormInterface( this );
    this->aRobot = new ChatRobot();
    this->aRobot->SetLogger( this->mp_Interface );
   // this->aRobot->Introduce();
}
//---------------------------------------------------------------------------
__fastcall  TFormInterface::TFormInterface( TForm1 *ContainerForm )
{
    this->mpContainerForm = ContainerForm;
}
//---------------------------------------------------------------------------
void __fastcall TFormInterface::Log(TDateTime LogTime, const AnsiString &Sender, const AnsiString &Info )
{
    this->mpContainerForm->mbChatList->Lines->Add( Sender + TAG_WHEN + DateTimeToStr( LogTime ) + TAG_SAY + ":\r\n" + Info + "\r\n" );
}         //每次发送一条则增加一行             //發送者     於          時間                     說         回車    用戶發送的消息
//---------------------------------------------------------------------------
__fastcall TForm1::~TForm1()
{
   delete this->mp_Interface;
   delete this->aRobot;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::btnSendClick(TObject *Sender)
{
   if(!this->mbMyInfo->Text.IsEmpty())
    {
    this->mp_Interface->Log( Now(), DEF_YOUR_NAME , this->mbMyInfo->Text );
           //用戶Memo        當前時間   用戶名字             Memo裏的消息
    this->aRobot->Talk( this->mbMyInfo->Text );
    }
    else
         {
           ShowMessage("你输入的内容为空!");
           this->mbMyInfo->SetFocus();
         }
    this->mbMyInfo->Clear();
    this->mbMyInfo->SetFocus();

}          //用戶發送一句話後機器人要回復一句
//---------------------------------------------------------------------------
void __fastcall TForm1::A1Click(TObject *Sender)
{
        frmAbout->ShowModal();//以模态方式显示
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCloseQuery(TObject *Sender, bool &CanClose)
{
        if(MessageDlg("您真要退出程序吗!",mtConfirmation,TMsgDlgButtons()<<mbOK<<mbCancel,0)==mrCancel)
             CanClose = false;
        else
             CanClose = true;    //询问用户是否真要退出程序,如果用户未保存信息则可以选择否而不退出;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::C2Click(TObject *Sender)
{
        mbChatList->CopyToClipboard();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::actSaveInfoExecute(TObject *Sender)
{
       if(SaveDialog->Execute())
             this->mbChatList->Lines->SaveToFile(SaveDialog->FileName);

}
//---------------------------------------------------------------------------

void __fastcall TForm1::actExitExecute(TObject *Sender)
{
        this->Close();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::N3Click(TObject *Sender)
{
        this->mbChatList->SelectAll();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::actsetshuxingExecute(TObject *Sender)
{
        robotdialog->ShowModal();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::actpasteExecute(TObject *Sender)
{
        this->mbChatList->PasteFromClipboard();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormActivate(TObject *Sender)
{
        robotdialog->robotchat->loadfrominifiles();
        this->aRobot->Introduce();
        this->mbMyInfo->SetFocus();
}
//---------------------------------------------------------------------------


void __fastcall TForm1::actHelpExecute(TObject *Sender)
{
        frmHelp->ShowModal();        
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -