如何遍历当前窗体所有组件,并得到属性!
如何遍历当前窗体所有组件,并得到所有组件的属性!不知大家有什么好方法!
[解决办法]
要用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;
}