給你一個範例
// Unit1.h
//--------------------------------------------------------------------------- #ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include
#include
#include
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
void __fastcall FormDestroy(TObject *Sender);
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
// 自訂一個Class
class TestClass : public System::TObject
{
public:
int iTest;
}; //---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
/////////////////////////////////////////////////////////////////////////////
// Unit1.cpp
//--------------------------------------------------------------------------- #include
#pragma hdrstop #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm" TForm1 *Form1;
TestClass* test;
TList* list;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
test = new TestClass();
list = new TList();
// 把自訂的Class加入TList
list->Add(test);
}
//--------------------------------------------------------------------------- void __fastcall TForm1::FormDestroy(TObject *Sender)
{
delete test;
delete list;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
// 取得加入TList的Class 名稱
AnsiString szClassName = ((TObject*)list->Items[0])->ClassName();
ShowMessage(szClassName);
}
//---------------------------------------------------------------------------