我的一个获取 Form RTTI 信息的小例子

来源:互联网 发布:使用模板编写sql语句 编辑:程序博客网 时间:2024/06/07 05:56

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
 uses typInfo;
{$R *.dfm}

procedure getPropInfomation(aclass:Tobject;aStrings:tstrings);
var
  PropCount :integer;
  PropStr:string;
  PropList : PPropList;
  i:integer;

  s:string;
begin
  Propcount := getTypeData(aclass.ClassInfo).PropCount;
  getmem(propList,propcount*sizeof(TPropInfo));
  getProplist(aclass.classinfo,PropList);
  for i:=0 to PropCount-1 do
  begin
    if PropList[i].PropType^.Kind <> typinfo.tkMethod then
    begin
      s := PropList[i].Name+'     '+ PropList[i].PropType^.Name;
      aStrings.Add(s);
    end;
   // PropStr :='PropName:='+Propstr+PropList[i]^.Name+'    TypeName:='+Proplist[i]^.propKind^.Name;
  end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
  getPropInfomation(form1,memo1.Lines);
end;

end.

原创粉丝点击