Q&A

  • 하위 프러퍼티 읽어오기....
안녕하세요.
아래와 같이 하여 프러퍼티 정보를 읽어 올수 있는데요.. 못가져 오는것들이 있더라구요.. 예를 들면 Font 같은거요. 이런건 하위에 또다른 프러퍼티 들이있잖아요.. 이렇건 어떻게 읽어와야 하나요..?


uses TypInfo;

procedure ObjectInspector(
Obj : TObject;
Items : TStrings );
var
n : integer;
PropList : TPropList;
begin
n := 0;
GetPropList(
Obj.ClassInfo,
tkProperties + [ tkMethod ],
@PropList );
while( (Nil <> PropList[ n ]) and
(n < High(PropList)) ) do
begin
Items.Add(
PropList[ n ].Name + ': ' +
PropList[ n ].PropType^.Name );
Inc( n );
end;
end;


예제) ObjectInspector( ListBox1, ListBox1.Items );




procedure GetClassProperties(AClass: TObject; AStrings: TStrings);
{ This method retrieves the property names and types for the given
object
and adds that information to the AStrings parameter. }
var
PropList: PPropList;
ClassTypeInfo: PTypeInfo;
ClassTypeData: PTypeData;
i: integer;
NumProps: Integer;
begin

ClassTypeInfo := AClass.ClassInfo;
ClassTypeData := GetTypeData(ClassTypeInfo);

if ClassTypeData.PropCount <> 0 then
begin
// allocate the memory needed to hold the references to the
TPropInfo
// structures on the number of properties.
GetMem(PropList, SizeOf(PPropInfo) * ClassTypeData.PropCount);
try
// fill PropList with the pointer references to the TPropInfo
structures
GetPropInfos(AClass.ClassInfo, PropList);
for i := 0 to ClassTypeData.PropCount - 1 do
// filter out properties that are events ( method pointer
properties)
if not (PropList[i]^.PropType^.Kind = tkMethod) then
AStrings.Add(Format('%s: %s', [PropList[i]^.Name,
PropList[i]^.PropType^.Name]));

// Now get properties that are events (method pointer
properties)
NumProps := GetPropList(AClass.ClassInfo, [tkMethod], PropList);
if NumProps <> 0 then begin
AStrings.Add('');
AStrings.Add(' EVENTS ================ ');
AStrings.Add('');
end;
// Fill the AStrings with the events.
for i := 0 to NumProps - 1 do
AStrings.Add(Format('%s: %s', [PropList[i]^.Name,
PropList[i]^.PropType^.Name]));

finally
FreeMem(PropList, SizeOf(PPropInfo) * ClassTypeData.PropCount);
end;
end;

end;









0  COMMENTS