📄 rttiinfo.pas
字号:
unit rttiinfo;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, typinfo, ExtCtrls, dsgnintf;
type
TRTTIForm = class(TForm)
lvTypeInfo: TListView;
Button1: TButton;
lvPropInfo: TListView;
Label1: TLabel;
Label2: TLabel;
RadioGroup1: TRadioGroup;
chkAutoUpdate: TCheckBox;
chkDialog: TCheckBox;
chkMultiSelect: TCheckBox;
chkReadOnly: TCheckBox;
chkSortList: TCheckBox;
chkSubProperties: TCheckBox;
chkValueList: TCheckBox;
chkRevert: TCheckBox;
Label3: TLabel;
edCompEdit: TEdit;
private
{ Private declarations }
procedure WriteClassData(Info: PTypeInfo; Data: PTypeData);
procedure WritePropInfo(Info: PPropInfo);
procedure WritePropEditorInfo(Editor: TPropertyEditor);
public
{ Public declarations }
procedure WriteTypeInfo(Info: PTypeInfo; PropName:string; PropEditor: TPropertyEditor);
end;
var
RTTIForm: TRTTIForm;
implementation
{$R *.DFM}
{$Include handel.inc}
procedure TRTTIForm.WriteClassData(Info: PTypeInfo; Data: PTypeData);
var
Item:TListItem;
begin
lvTypeInfo.Items.Clear;
if Info = nil then Exit;
with Data^ do
begin
Item:= lvTypeInfo.Items.Add;
Item.Caption:= 'Class Type';
Item.SubItems.Add(ClassType.ClassName);
Item:= lvTypeInfo.Items.Add;
Item.Caption:= 'ParentInfo';
if ParentInfo = nil then
Item.SubItems.Add('nil')
else Item.SubItems.Add(ParentInfo^.Name);
Item:= lvTypeInfo.Items.Add;
Item.Caption:= 'PropCount';
Item.SubItems.Add(IntToStr(PropCount));
Item:= lvTypeInfo.Items.Add;
Item.Caption:= 'Unit Name';
Item.SubItems.Add(UnitName);
end;
end;
procedure TRTTIForm.WritePropInfo(Info: PPropInfo);
var
Item:TListItem;
begin
lvPropInfo.Items.Clear;
if Info = nil then Exit;
with Info^ do
begin
Item:= lvPropInfo.Items.Add;
Item.Caption:= 'Name';
Item.SubItems.Add(Name);
Item:= lvPropInfo.Items.Add;
Item.Caption:= 'TypeName';
Item.SubItems.Add(PropType^.Name);
Item:= lvPropInfo.Items.Add;
Item.Caption:= 'GetProc';
Item.SubItems.Add(Format('%p', [GetProc]));
Item:= lvPropInfo.Items.Add;
Item.Caption:= 'SetProc';
Item.SubItems.Add(Format('%p', [SetProc]));
Item:= lvPropInfo.Items.Add;
Item.Caption:= 'Index';
Item.SubItems.Add(Format('%d', [Index]));
Item:= lvPropInfo.Items.Add;
Item.Caption:= 'Default';
Item.SubItems.Add(Format('%d', [Default]));
Item:= lvPropInfo.Items.Add;
Item.Caption:= 'NameIndex';
Item.SubItems.Add(Format('%d', [NameIndex]));
end;
end;
procedure TRTTIForm.WritePropEditorInfo(Editor: TPropertyEditor);
var
Attr: TPropertyAttributes;
begin
if Editor = nil then Exit;
Attr:= Editor.GetAttributes;
chkAutoUpdate.Checked := (paAutoUpdate in Attr);
chkDialog.Checked := (paDialog in Attr);
chkMultiSelect.Checked := (paMultiSelect in Attr);
chkReadOnly.Checked := (paReadOnly in Attr);
chkSortList.Checked := (paSortList in Attr);
chkSubProperties.Checked := (paSubProperties in Attr);
chkValueList.Checked := (paValueList in Attr);
end;
procedure TRTTIForm.WriteTypeInfo(Info: PTypeInfo; PropName:string; PropEditor: TPropertyEditor);
var
Data: PTypeData;
PropInfo: PPropInfo;
Comp: TComponent;
CompEditor: TComponentEditor;
begin
Data:= GetTypeData(Info);
case Info^.Kind of
tkClass: WriteClassData(Info, Data);
end;
PropInfo:= GetPropInfo(Info, PropName);
WritePropInfo(PropInfo);
WritePropEditorInfo(PropEditor);
Comp:= TComponent(PropEditor.GetComponent(0));
{$IFDEF DELPHI3}
CompEditor:= GetComponentEditor(Comp, TFormDesigner(Designer));
{$ENDIF}
{$IFDEF DELPHI4}
CompEditor:= GetComponentEditor(Comp, IFormDesigner(Designer));
{$ENDIF}
if CompEditor <> nil then
edCompEdit.Text:= CompEditor.ClassName;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -