读书人

怎么遍历当前窗体所有组件,并得到属性

发布时间: 2012-02-19 19:43:39 作者: rapoo

如何遍历当前窗体所有组件,并得到属性!
如何遍历当前窗体所有组件,并得到所有组件的属性!不知大家有什么好方法!

[解决办法]
要用RTTI。借shadowstar的答案。
在如下修改
TPropList PropList;
GetPropListBCB6Ex(Control,PropList);
Memo1-> Text = PropList-> Text;


int GetPropListBCB6Ex(TObject* AxObject, PPropList Result);
//=====================================
int GetPropListBCB6Ex(TObject* AxObject, PPropList Result)
{
int i,j;
int ListCount,Count=0;
try
{
Count= GetTypeData((PTypeInfo)(AxObject-> ClassInfo()))-> PropCount;
ListCount = Count;

PPropList List = new PPropInfo[Count+1];

TStringList *pDesList = new TStringList();
TStringList *pSrcList = new TStringList();


GetPropInfos((PTypeInfo)(AxObject-> ClassInfo()), List);


for (i = 0; i < Count; i++)
{
pDesList-> Add(List[i]-> Name);
pSrcList-> Add(List[i]-> Name);
}
pDesList-> Sorted = !pDesList-> Sorted;


for ( i = 0; i < Count; i++)
{
for ( j = 0; j < Count; j++)
{
if(!CompareStr(pDesList-> Strings[i],pSrcList-> Strings[j] ))
{
Result[i]= List[j];
}
}
}


delete[] List;
delete pDesList;
delete pSrcList;
}
catch(...)
{

}
return ListCount;
}

读书人网 >C++ Builder

热点推荐