Thx to wlmmlw ,用你的方法又碰到新的问题 :
我把你的代码改成(如下),运行之后很多在属性框中没有的属性出来了,
我只想显示属性框中的属性和其值,不论其值类型是字符还是数值(用你的
代码只能获取String型的数值 ) ,这要咱办?:
procedure TForm1.aTButtonClick(Sender: TObject);
var
pProps: PPropList;
nTotProps, nProps, I: Integer;
StrList :TStringList;
begin
//get the total number of properties
nTotProps := GetTypeData(ClassInfo).PropCount;
//allocate the required memory
GetMem(pProps, sizeof(PPropInfo) * nTotProps);
try
//fill the pProps with a filtered list
nProps := GetPropList(ClassInfo, [tkUnknown, tkChar, tkEnumeration,
tkString, tkSet, tkClass, tkWChar, tkLString, tkWString,
tkVariant, tkArray, tkRecord, tkInterface, tkDynArray], pProps);
StrList :=TStringList.Create;
for i :=0 to nTotProps-1 do
begin
try
GetPropertyToList(aTButton,pProps^,StrList,true);
except
continue ;
end;
end;
ListBox1.Items :=StrList;
Caption := IntTostr(ListBox1.Items.count)
finally
FreeMem(pProps, sizeof(PPropInfo) * nTotProps);
end;
end;
procedure TForm1.GetPropertyToList(Instance: TObject; PropInfo: PPropInfo;
var rStrList:TStringList;NeedValue:Boolean=false);
begin
if PropInfo <> nil then
begin
begin
rStrList.Add (PropInfo^.PropType^.Name );
if NeedValue then
rStrList.Strings [rStrList.Count -1]:=rStrList.Strings [rStrList.Count -1]+
'Value ='+ GetStrProp(Instance, PropInfo);
end;
end;
end;
end.