📄 serverunit.cpp
字号:
// Direct Oracle Access - Server
// Allround Automations
// support@allroundautomations.nl
// http://www.allroundautomations.nl
//
// This application demonstrates:
// - The Server part of a 3 Tier application
// - The use of the TOracleProvider component
// This is a tray-icon application, it will show up as an icon on the
// bottom right of your screen.
// Click it to display the main form.
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ServerUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "Oracle"
#pragma link "OracleData"
#pragma resource "*.dfm"
TMainForm *MainForm;
//---------------------------------------------------------------------------
int Connections = 0; // Count the number of connections
TCloseAction CloseAction = caNone; // Action for the FormClose method
const WM_TRAYICON = WM_USER + 1; // TrayIcon message
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
// The next part handles the TrayIcon
bool __fastcall TMainForm::AddIcon()
{
TrayIconData.cbSize = sizeof(TNotifyIconData);
TrayIconData.hWnd = Handle;
TrayIconData.uID = 0;
TrayIconData.uFlags = NIF_MESSAGE + NIF_ICON + NIF_TIP;
TrayIconData.hIcon = Icon->Handle;
strcpy(TrayIconData.szTip, "Server Application");
TrayIconData.uCallbackMessage = WM_TRAYICON;
return (Shell_NotifyIcon(NIM_ADD, &TrayIconData));
}
//---------------------------------------------------------------------------
bool __fastcall TMainForm::DeleteIcon()
{
return (Shell_NotifyIcon(NIM_DELETE, &TrayIconData));
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::TrayIconClick()
{
Application->ShowMainForm = true;
Visible = true;
SetForegroundWindow(Handle);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::WndProc(Messages::TMessage &Message)
{
if (Message.Msg == WM_TRAYICON)
{
switch (Message.LParam)
{
case WM_LBUTTONUP : TrayIconClick();
case WM_RBUTTONUP : TrayIconClick();
}
}
else
{
TForm::WndProc(Message);
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
AddIcon();
LogMemo->Clear();
UpdateStatusLine(0);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormDestroy(TObject *Sender)
{
DeleteIcon();
}
//---------------------------------------------------------------------------
// The default close simply hides the main form
void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction &Action)
{
Action = CloseAction;
if (Action == caNone) Visible = false;
}
//---------------------------------------------------------------------------
// Force this application to stop
void __fastcall TMainForm::ShutDownButtonClick(TObject *Sender)
{
CloseAction = caFree;
Close();
CloseAction = caNone;
}
//---------------------------------------------------------------------------
// Display a line in the TMemo
void __fastcall Log(AnsiString S)
{
S = FormatDateTime("hh:mm:ss ", Now()) + S;
if (MainForm != NULL) MainForm->LogMemo->Lines->Add(S);
}
//---------------------------------------------------------------------------
// Display the number of connections
void __fastcall UpdateStatusLine(int Change)
{
AnsiString S;
Connections = Connections + Change;
if (MainForm != NULL)
{
S = " " + IntToStr(Connections) + " Connection";
if (Connections != 1) S = S + "s";
MainForm->StatusPanel->Caption = S;
}
}
//---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -