谁知道用什么方法可以列出某一个控件的所有属性么 比如点击一下BUTTON就可以获得她的所有属性。不知DELPHI可不可以做到这一点哪。

解决方案 »

  1.   

    uses typinfovar
      fpropList: PPropList;
      fPropCount,i: integer;
    begin
      fPropCount := GetTypeData(button2.ClassInfo).PropCount;
      fPropList  := Nil;
      if fPropCount > 0 then
      begin
        GetMem(fPropList, fPropCount * SizeOf(Pointer));
        GetPropInfos(button2.ClassInfo, fPropList);
      end;
      for i := 0 to fPropCount - 1 do
        listbox1.Items.Add(fproplist[i].Name);建议学习一下rtti相关只是
      

  2.   

    uses typinfo
      TYPINFO
      单元中还有一个函数,应为GET开头,后面忘了,前段时间用过
      去单元里查一下,即可
      

  3.   

    function GetPropValue(Instance: TObject; const PropName: string;
      PreferStrings: Boolean = True): Variant;procedure SetPropValue(Instance: TObject; const PropName: string;
      const Value: Variant);
      

  4.   

    uses typinfoprocedure 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;