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

📄 mainunit.cpp

📁 Direct Oracle Access 非常好的Oracle数据库直接访问组件包 支持个版本的Delphi及C++ Builder 有源码
💻 CPP
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "MainUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "Oracle"
#pragma resource "*.dfm"
TQueueDemoForm *QueueDemoForm;
//---------------------------------------------------------------------------
__fastcall TQueueDemoForm::TQueueDemoForm(TComponent* Owner)
    : TForm(Owner)
{
}

//---------------------------------------------------------------------------
void __fastcall TQueueDemoForm::Display(AnsiString Msg)
{
  ReceiveMemo->Lines->Add(Msg);
}
//---------------------------------------------------------------------------
// Connect the sessions and create the queue objects if necessary
void __fastcall TQueueDemoForm::StartQueue()
{
  try
  {
    // Connect the session if necessary
    if (!SendSession->Connected)
    {
      QueueOkay = false;
      Logon->Execute();
      if (SendSession->Connected)
      {
        QueueOkay = true;
        // Copy logon properties and also connect the receiving session
        ReceiveSession->LogonUsername = SendSession->LogonUsername;
        ReceiveSession->LogonPassword = SendSession->LogonPassword;
        ReceiveSession->LogonDatabase = SendSession->LogonDatabase;
        ReceiveSession->LogOn();
        QueueCheckQuery->Execute();
        // Check if the queue exists
        if (QueueCheckQuery->Field(0) == 0)
        {
          // If not, create it
          ShowMessage("Press OK to create the demo queue");
          // If user has the AQ_ADMINISTRATOR_ROLE role, create the objects
          RoleCheckQuery->Execute();
          if (RoleCheckQuery->Field(0) == 0)
            ShowMessage("You do not have the role ''AQ_ADMINISTRATOR_ROLE'', which\n"
                        "is a requirement to create queue objects. Please obtain\n"
                        "this role and run this demo again.");
          else
            CreateQueueScript->Execute();
          // Check if the queue exists now
          QueueCheckQuery->Execute();
          // If not, exit
          if (QueueCheckQuery->Field(0) == 0)
          {
            Application->Terminate();
            QueueOkay = false;
          }
        }
      }
    }
  }
  catch (Exception &exception)
  {
    ShowMessage(exception.Message);
    QueueOkay = false;
  }
  if (QueueOkay && !ReceiveQueue->ThreadIsRunning) ReceiveQueue->StartThread();
}
//---------------------------------------------------------------------------
// Send the message
void __fastcall TQueueDemoForm::SendButtonClick(TObject *Sender)
{
  // Try to connect, create the queue objects, and start it if necessary
  StartQueue();
  if (ReceiveQueue->ThreadIsRunning)
  {
    // Create the message
    SendQueue->Payload->SetAttr("message_text", SendMessageEdit->Text);
    SendQueue->Payload->SetAttr("message_type", "Info");
    // Send it
    SendQueue->Enqueue();
    // Commit
    SendSession->Commit();
  }
}
//---------------------------------------------------------------------------
// Enable/Disable the send button
void __fastcall TQueueDemoForm::SendMessageEditChange(TObject *Sender)
{
  SendButton->Enabled = (SendMessageEdit->Text != "");
}
//---------------------------------------------------------------------------
// Display a received message
void __fastcall TQueueDemoForm::ReceiveQueueThreadDequeued(TOracleQueue *Sender)
{
  Display("Message received: " + Sender->MessageProperties->MsgId);
  Display("Message enqueued: " + FormatDateTime("c", Sender->MessageProperties->EnqueueTime));
  Display("Message text    : " + Sender->Payload->GetAttr("message_text"));
  Display("");
}
//---------------------------------------------------------------------------
// Display that the thread has started
void __fastcall TQueueDemoForm::ReceiveQueueThreadStart(TOracleQueue *Sender)
{
  Display(Sender->Name + " started.");
  Display("");
}
//---------------------------------------------------------------------------
// Display that the thread has stopped
void __fastcall TQueueDemoForm::ReceiveQueueThreadStop(TOracleQueue *Sender)
{
  if (!ComponentState.Contains(csDestroying))
  {
    Display(Sender->Name + " stopped.");
    Display("");
  }
}
//---------------------------------------------------------------------------

void __fastcall TQueueDemoForm::CreateQueueScriptError(
      TOracleScript *Sender)
{
  ShowMessage(Sender->CurrentCommand->ErrorMessage);
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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