如题.通过代码实现.

解决方案 »

  1.   

    通过RTTI可以获得一个类的所有Published属性
    var
      mTypeInfo: PTypeInfo;
      mTypeData: PTypeData;
      mPropList: PPropList;
      mPropInfo: PPropInfo;
      mPropCount, i: Integer;
    begin
      mTypeInfo := Form1.ClassInfo;  mTypeData := GetTypeData(mTypeInfo);
      if mTypeInfo^.Kind <> tkClass then Exit;  mPropCount := mTypeData^.PropCount;
      if mPropCount <= 0 then Exit;  GetMem(mPropList, mPropCount * SizeOf(PPropList));
      try
        GetPropInfos(mTypeInfo, mPropList);
        for i := 0 to mPropCount - 1 do
        begin
          mPropInfo := mPropList^[i];
          ShowMessage(mPropInfo^.Name);
        end;
      finally
        FreeMem(mPropList, mPropCount * SizeOf(PPropList));
      end;
    end;
      

  2.   

    肯定是可以的,只是我不会.
    代码提示都可以做到,cnpack的代码助手也可以做到.
      

  3.   

    通过RTTI可以获得一个类的所有Published属性
    var
      mTypeInfo: PTypeInfo;
      mTypeData: PTypeData;
      mPropList: PPropList;
      mPropInfo: PPropInfo;
      mPropCount, i: Integer;
    begin
      mTypeInfo := Form1.ClassInfo;  mTypeData := GetTypeData(mTypeInfo);
      if mTypeInfo^.Kind <> tkClass then Exit;  mPropCount := mTypeData^.PropCount;
      if mPropCount <= 0 then Exit;  GetMem(mPropList, mPropCount * SizeOf(PPropList));
      try
        GetPropInfos(mTypeInfo, mPropList);
        for i := 0 to mPropCount - 1 do
        begin
          mPropInfo := mPropList^[i];
          ShowMessage(mPropInfo^.Name);
        end;
      finally
        FreeMem(mPropList, mPropCount * SizeOf(PPropList));
      end;
    end;
    利用VMt获取方法表.