|
안녕하세요 에보니에요.
말은 필요 없고 직접 보여 드리져. 저의 경우 업무 로직은 전부 클래스화 시킴니다.
다음 클래스는 제가 만든 간단한 클래스중의 하나인데...(식탁 클래스임) 함 보세요
클래스 헤더 화일입니다.
#ifndef TableH
#define TableH
#include <Classes.hpp>
#include <StdCtrls.hpp>
enum TableMode
{
ADDMENU,
POPMENU,
READ,
MERGE,
SEPARATE,
MOVE,
CHECKOUT,
RESERVE
};
#include <DB.hpp>
#include <DBTables.hpp>
class Table
{
private:
TQuery *Data; // Database Connect, Access.
void __fastcall Configure(); // Configure all property.
public:
__fastcall Table(); // Constructor.
__fastcall ~Table(); // Destructor.
// Proprty of this class.
int Index; // Current Index.
int Target; // Target Index.
int Number; // Entire Numbers of Table.
int Total; // Total Money of Table.
int Master; // Number of Master Table.
TableMode Mode; // Current table Mode.
String InBox; // Current table Input.
String Code; // Code purified by InBox.
String CurrentMenu; // Current Menu.
String State; // Current Table State.
String AppPath; // Path of Application
TStringList *Mois; // Menu list of Current Table.
TStringList *Info; // State list of Current Table.
// Method of this class.
void __fastcall Activate(); // Activate Target Table.
void __fastcall Initialize(); // Initialize Target Table.
void __fastcall CheckOut(); // Check out Current Table.
void __fastcall Save(); // Save Target Table.
void __fastcall Load(); // Load Target Table.
void __fastcall Merge(); // Merge Current Table With Target Table.
void __fastcall Separate(); // Separate Target Table from Current Table.
void __fastcall Transfer(); // Transfer Current Table to Target Table.
void __fastcall Reserve(); // Reserve Target Table.
void __fastcall ReleaseMergeChild(); // Release Merging child table.
void __fastcall TransferMergeChild(); // Transfer Merging child table.
void __fastcall AddMenu(String MenuName, int Volume);
void __fastcall PopMenu(String MenuName, int Volume);
void __fastcall PopMenuInMaster(String Menu, int Volume);
void __fastcall MenuClear(); // Clear Menu List.
bool __fastcall ExistMenu(String MenuCode); // Check whether Item is in DB.
bool __fastcall GetMenuName(String Code); // Get Menu Name from Code.
int __fastcall GetMenuPrice(String MenuName); // Get Menu Price from Menu Name.
bool __fastcall CheckCode(); // Check Input.
bool __fastcall IdentifyCode(); // Identify Code and Mode.
};
#endif
cpp 소스에서는 생성자와 파괴자만 보여 드릴께여.
#include "Table.h"
__fastcall Table::Table()
{
Index = 1;
Target = 1;
Master = 0;
Total = 0;
AppPath = ExtractFileDir(Application->ExeName);
Mois = new TStringList();
Info = new TStringList();
Data = new TQuery(Application);
Data->DatabaseName = AppPath + "\\Data\\";
}
__fastcall Table::~Table()
{
delete Mois, Info, Data;
}
이하 헤더에서 선언한 멤버함수들의 임플리멘테이션~
............................................
그리고 실제 폼에서
TMainForm *MainForm;
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
table = new Table();
table->Mode = ADDMENU;
}
이렇게 하면 폼이 파괴될때 자동으로 파괴자가 호출이 됩니다.
생성자와 파괴자 부분에서 님이 필요하신 답변이 있는듯 하군요.
그럼 즐 프 하세용~ *^0^*
|