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

📄 main.cpp

📁 Direct Oracle Access 非常好的Oracle数据库直接访问组件包 支持个版本的Delphi及C++ Builder 有源码
💻 CPP
字号:
// Direct Oracle Access - PkgApply
// Allround Automations
// support@allroundautomations.nl
// http://www.allroundautomations.nl
//
// This application demonstrates:
// - The use of the OnApplyRecord event
// - The use of the TOraclePackage component
// - The use of a cursor variable in a dataset
//
// NOTE: You must run DeptAPI.pck through SQL*Plus before running this demo
// ========================================================================
//
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "Oracle"
#pragma link "OracleData"
#pragma resource "*.dfm"
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::DeptDataSetApplyRecord(TOracleDataSet *Sender,
      char Action, bool &Applied, AnsiString &NewRowId)
{
  AnsiString Call = "";

  // For locks, updates and deletes we need the old deptno value to
  // identify a dept record
  switch(Action)
  {
    case 'L':
      Call = "DeptAPI.LockRecord(:Old_DeptNo)";
      break;
    case 'I':
      Call = "DeptAPI.InsertRecord(:DeptNo, :DName, :Loc)";
      break;
    case 'U':
      Call = "DeptAPI.UpdateRecord(:Old_DeptNo, :DeptNo, :DName, :Loc)";
      break;
    case 'D':
      Call = "DeptAPI.DeleteRecord(:Old_DeptNo)";
      break;
  }
  // Build a PL/SQL block with a call to a DeptAPI procedure;
  if (Call != "")
  {
    Query->Clear();
    Query->SQL->Add("begin");
    Query->SQL->Add("  " + Call + ";");
    Query->SQL->Add("end;");
    // Declare the variables
    Sender->DeclareQueryVariables(Query);
    // Set the values of the variables
    Sender->SetQueryVariables(Query);
    // Execute the query
    Query->Execute();
    // The procedure can determine a new DeptNo value, so we need to refresh it
    if (Query->VariableIndex("DeptNo") >= 0)
      DeptNo->Value = Query->GetVariable("DeptNo");
  }
  // Notify to the dataset the we have applied the record
  Applied = TRUE;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::OrderGroupClick(TObject *Sender)
{
  // Set the p_order variable to the name of the corresponding field
  DeptDataSet->SetVariable("p_order", DeptDataSet->Fields->Fields[OrderGroup->ItemIndex]->FieldName);
  // Refresh the dataset
  DeptDataSet->Refresh();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
  MainLogon->Execute();
  if (MainSession->Connected) DeptDataSet->Open();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ShowCallsCheckClick(TObject *Sender)
{
  Query->Debug = ShowCallsCheck->Checked;
  DeptDataSet->Debug = ShowCallsCheck->Checked;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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