uses Rtti;

function GetParentClassName(AClass: TClass): string;
begin
  Result := AClass.ClassName;
  while AClass.ClassParent <> nil do
  begin
    AClass := AClass.ClassParent;
    Result := Result + ' < ' + AClass.ClassName;
  end;
end;

procedure GetPropertyMethodList(AForm: TComponent; OutList: TStrings; Exclude: string = '');
var
  R: TRttiContext;
  T: TRttiType;
  p: TRttiProperty;
  m: TRttiMethod;
  f: TRttiField;
  X: TObject;
  i: Integer;
begin
  for i := 1 to AForm.ComponentCount - 1 do
  begin
    X := AForm.Components[i];
    if X.ClassName = Exclude then Continue;
    T := R.GetType(X.ClassType);
    OutList.Add(GetParentClassName(X.ClassType));
    OutList.Add('------------------------------------');

    for p in T.GetProperties do OutList.Add(p.ToString);
    OutList.Add('');

    for m in T.GetMethods do OutList.Add(m.ToString);
    OutList.Add('========================================================================');
    OutList.Add('');
  end;
end;

procedure GetClassPropertyMethodList(AClass: TClass; OutList: TStrings);
var
  R: TRttiContext;
  T: TRttiType;
  p: TRttiProperty;
  m: TRttiMethod;
  f: TRttiField;
begin
  T := R.GetType(AClass);
  OutList.Add(GetParentClassName(AClass));
  OutList.Add('------------------------------------');

  for p in T.GetProperties do OutList.Add(p.ToString);
  OutList.Add('');

  for m in T.GetMethods do OutList.Add(m.ToString);
  OutList.Add('========================================================================');
  OutList.Add('');
end;

procedure TIWForm1.IWAppFormCreate(Sender: TObject);
var
  X: TClass;
begin
//  GetPropertyMethodList(Self, IWMemo1.Lines);
  X := TClass(TIWServerControllerBase);
  GetClassPropertyMethodList(X, IWMemo1.Lines);
end;


posted on 2014-05-30 09:45  万一  阅读(273)  评论(0)    收藏  举报