Get all properties and methods of the control

zhaozj2021-02-16  78

Uses unit Typinfo before obtaining all the properties and methods of the control, simple

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.ClassType.ClassInfo; ClassTypeData: = GetTypeData (ClassTypeInfo); if ClassTypeData.PropCount <> 0 then begin GetMem (propList, SizeOf (PPropInfo) * ClassTypeData.PropCount); try GetPropInfos ( Aclass.classinfo, proplist; for i: = 0 to classtypedata.propcount - 1 do if not (Proplist [i] ^. PropType ^ .kind = tkmethod) THEN Astrings.Add (Format ('% s:% s ", [PROPLIST [I] ^., Proplist [i] ^. PropType ^ .name]); 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 assengings.add (Format ('% s:% s', [pROPLIST [i] ^. Name, Proplist [i] ^. PropType ^ .name]));

Finally FreeMem (PROPLIST, SIZEOF (PPROPInfo) * ClassTypedTyPedata.propcount; end; end; end;

转载请注明原文地址:https://www.9cbs.com/read-17563.html

New Post(0)