本文中包含了一些常用的代码片断,看看想想或许有他山之石可以攻玉的可能。
删除别名中所有的表、纯虚函数、虚函数、启动页面、指针、为指针解除引用、表的For循环变量与常量的声明、检查表是否存在、组件的类名、剪贴板中的文字、字符流、检查表是否已打开表的状态操作、改变PageControl的标签、向Query传递参数 日期属性 绘制状态条删除别名中所有的表
void TData::CleanTemp()
{
TStringList *myTables = new TStringList();
TTable *Table = new TTable(this);
try
{
Session->GetTableNames("Temp", "", True, False, myTables);
}
catch (...) {}
// AnsiString str = myTables->GetText();
// ShowMessage(str);
for(int count=0; count < myTables->Count; count++)
{
Table->DatabaseName = "Temp";
Table->TableName = myTables->Strings[count];
Table->Close();
Table->DeleteTable();
}
delete myTables;
delete Table;
}
纯虚函数
//纯虚函数只在基类中出现,而在子类中必须有
//与其匹配的成员函数。程序中申明的子类的实例
//必须为基类中的每一个纯虚函数提供一个重载的成员函数。
class TBaseClass
{
public:
virtual void Display() = 0;
};
class TDerivedClass : public TBaseClass
{
public:
void Display() { ShowMessage("From Derived"); }
};
class TSecondDerivedClass : public TDerivedClass
{
public:
void Display() { ShowMessage("From Second Derived"); }
};
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TDerivedClass dc; dc.Display();// "From Derived"
TSecondDerivedClass sc; TBaseClass* bc = ≻
bc->Display(); // "From Second Derived"
}
虚函数
//虚函数作为其他类的父类的成员函数。
//如果继承子类成员函数中存在与父类成员函数完全相同的函数,
//子类中的成员函数永远有效。
class Base
{
public:
virtual void Display() { ShowMessage("Base Class"); }
};
class DerivedOne : public Base
{
public:
void Display() { ShowMessage("DerivedOne"); }
};
class DerivedTwo : public Base
{
public:
void Display() { ShowMessage("DerivedTwo"); }
};
Base* pBases[10];
int count = 0;
DerivedOne aDerOne;
DerivedTwo aDerTwo;
pBases[count++] = &aDerOne;
pBases[count++] = &aDerTwo;
for( int i=0; i < count; i++ )
pBases[i]->Display();
启动页面
USEDATAMODULE("Datamod.cpp", DataModule);
USEFORM("about.cpp", AboutBox);
USEFORM("main.cpp", MainForm);
USEFORM("splash.cpp", SplashForm);
//---------------------------------------------------------------------------
#include "splash.h"
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
SplashForm = new TSplashForm(Application);
SplashForm->Show();
SplashForm->Update();
Application->Initialize();
Application->Title = "Example of Loading Splash Form";
Application->HelpFile = "SplashHelp.hlp";
Application->CreateForm(__classid(TMainForm), &MainForm);
Application->CreateForm(__classid(TDataModule), &DataModule
|