类信息

返回对象的所有属性,用列表返回


function TDataMod.GetClassProperties(AClass: TClass):TStrings;
var
  PropCount, I: SmallInt;
  PropList: PPropList;
  PropStr: string;
begin
  result := TStringList.Create;
  PropCount := GetTypeData(AClass.ClassInfo).PropCount;
  GetPropList(AClass.ClassInfo, PropList);
  for I := 0 to PropCount - 1 do
  begin
    case PropList[I]^.PropType^.Kind of
      tkClass : PropStr := '[Class] ';
      tkMethod : PropStr := '[Method]';
      tkSet : PropStr := '[Set] ';
      tkEnumeration: PropStr := '[Enum] ';
    else
      PropStr := '[Field] ';
      result.Add(PropList[I]^.Name);
    end;
  end;
  FreeMem(PropList);
end;

根据属性名赋属性值

SetPropValue(obj, fieldName, fieldValue);