我想創建一個表單,其類名爲字符串which has been asked about before,但我不想調用GetClass,我想使用Delphi的新RTTI功能。使用此代碼,我有TRttiType,但我不知道如何實例化它。 var
f:TFormBase;
ctx:TRttiContext;
lType:TRttiType;
begin
ctx :=
class A
{
protected:
int a;
public:
A();
A(int);
virtual void print()=0;
virtual ~A();
};
class B: public A
{
int b;
public:
B();
B(int,int); //initiali
我發現自己使用通用的運行時類型識別模式,特別是在編寫處理不同類型控件的代碼時。下面是模式: if (ctrl is ControlTypeEtc)
(ctrl as ControlTypeEtc).SomeMethod();
我這樣做是爲了避免做的情況下,一個NULL檢查爲運算符返回NULL。有沒有辦法簡化這到一個單一的操作?
可能重複: Is there a way to instantiate objects from a string holding their class name? 我寫了一個VBO模板類在OpenGL頂點緩衝區對象的工作。我正在爲C++編寫多個平臺。 我想在運行時從配置文件中設置類型。 例如 <vbo type="bump_vt" ... />
Vbo* pVbo = new Vbo<bu