请问给位Delphi高手,可以在运行时态取到VCL控件的属性列表吗?

解决方案 »

  1.   

    DDG的例子:
    unit MainFrm;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TMainForm = class(TForm)
        lbSamps: TListBox;
        memInfo: TMemo;
        procedure FormCreate(Sender: TObject);
        procedure lbSampsClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      MainForm: TMainForm;implementation
    uses TypInfo, Buttons;{$R *.DFM}
    procedure TMainForm.FormCreate(Sender: TObject);
    begin
      // Add some example enumerated types
      with lbSamps.Items do
      begin
        AddObject('TButtonState', TypeInfo(TButtonState));
        AddObject('TFormStyle', TypeInfo(TFormStyle));
        AddObject('Boolean', TypeInfo(Boolean));
      end;
    end;procedure TMainForm.lbSampsClick(Sender: TObject);
    var
      OrdTypeInfo: PTypeInfo;
      OrdTypeData: PTypeData;  TypeNameStr: String;
      TypeKindStr: String;
      MinVal, MaxVal: Integer;
      i: integer;
    begin
      memInfo.Lines.Clear;
      with lbSamps do
      begin    // Get the TTypeInfo pointer
        OrdTypeInfo := PTypeInfo(Items.Objects[ItemIndex]);
        // Get the TTypeData pointer
        OrdTypeData := GetTypeData(OrdTypeInfo);    // Get the type name string
        TypeNameStr := OrdTypeInfo.Name;
        // Get the type kind string
        TypeKindStr := GetEnumName(TypeInfo(TTypeKind), Integer(OrdTypeInfo^.Kind));    // Get the minimum and maximum values for the type
        MinVal := OrdTypeData^.MinValue;
        MaxVal := OrdTypeData^.MaxValue;
        // Add the information to the memo
        with memInfo.Lines do
        begin
          Add('Type Name: '+TypeNameStr);
          Add('Type Kind: '+TypeKindStr);      Add('Min Val: '+IntToStr(MinVal));
          Add('Max Val: '+IntToStr(MaxVal));      // Show the values and names of the enumerated types
          if OrdTypeInfo^.Kind = tkEnumeration then
            for i := MinVal to MaxVal do
              Add(Format('  Value: %d   Name: %s', [i, GetEnumName(OrdTypeInfo, i)]));    end;
      end;
    end;end.
      

  2.   

    to  newwen(wen) 
    可能我表达错了,我是说可以在运行时态取得VCL控件的所有Publish属性名字。比如“name”,“caption”,“left”……等等。
      

  3.   

    请参考如下代码~~uses TypInfo;procedure TForm1.Button1Click(Sender: TObject);
    var
      vPropList: PPropList;
      I: Integer;
    begin
      ListBox1.Clear;
      for I := 0 to GetPropList(Self, vPropList) - 1 do
        ListBox1.AddItem(vPropList[I].Name, TObject(vPropList[I]));
    end;嘻嘻嘻 想玩VCL的RTTI就去花时间了解TypInfo单元 嘻嘻嘻嘻