Rtti.TRttiType (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example is a Delphi VCL Forms Application that displays in a TTreeView component the RTTI that can be found for the TButton class.

TButton RTTI

Code

procedure TForm1.FormCreate(Sender: TObject);
var
  LContext: TRttiContext;
  LType: TRttiType;
  LMethod: TRttiMethod;
  LProperty: TRttiProperty;
  LField: TRttiField;
  LTreeNode1, LTreeNode2: TTreeNode;
begin
  LContext := TRttiContext.Create;
  try
    LType := LContext.GetType(TButton);
    LTreeNode1 := TreeView1.Items.AddChild(nil, LType.ToString);

    LTreeNode2 := TreeView1.Items.AddChild(LTreeNode1, 'Methods');
    for LMethod in LType.GetMethods do
    begin
      TreeView1.Items.AddChild(LTreeNode2, LMethod.ToString);
    end;

    LTreeNode2 := TreeView1.Items.AddChild(LTreeNode1, 'Properties');
    for LProperty in LType.GetProperties do
    begin
      TreeView1.Items.AddChild(LTreeNode2, LProperty.ToString);
    end;

    LTreeNode2 := TreeView1.Items.AddChild(LTreeNode1, 'Fields');
    for LField in LType.GetFields do
    begin
      TreeView1.Items.AddChild(LTreeNode2, LField.ToString);
    end;

    TreeView1.FullExpand;
  finally
    LContext.Free;
  end;
end;

Uses