Jump to content
PeterPanettone

Show the ancestors for a class?

Recommended Posts

Does MMX have a feature to show the ANCESTORS (e.g., in a hierarchical tree) for a specific known class?

Or is there any IDE addon that has such a  feature?

Share this post


Link to post

MMX can show the immediate ancestor of a class or interface. This is an option under the Order by item in context menu of the explorer content tree. As long as all ancestor are inside the same unit as the inspected class they are already visible in hierarchical view.

Share this post


Link to post

To solve this problem, I need to get e.g. Vcl.StdCtrls.TButton from TButton. How can I do that?

Edited by PeterPanettone

Share this post


Link to post
1 hour ago, PeterPanettone said:

Unfortunately, this does not allow me to show all the ancestors, e.g., of `TButton`.

Yes, and that is exactly what I wrote.  MMX can only display what is somewhere in the current unit. This includes the ancestor of a class, but not the ancestor of that.

20 minutes ago, PeterPanettone said:

To solve this problem, I need to get e.g. Vcl.StdCtrls.TButton from TButton. How can I do that?

I am not sure what you mean. If you Ctrl-Click on the type TButton in the source editor it will navigate you to the declaration of TButton in Vcl.StdCtrls.pas, but that is totally unrelated to MMX.

Share this post


Link to post

If you place the cursor in the TButton and press F1, help will appear. And in it the whole family tree. This applies to all standard components. No more for third-party components and custom.

Share this post


Link to post

You would need the source code

procedure TmainForm.RzButton1Click(Sender: TObject);
var ClassRef: TClass;
    S,sS: string;
begin
  ClassRef := Sender.ClassType;
  repeat
    sS := ClassRef.ClassName;
    S := S + #13#10 + sS;
    ClassRef := ClassREf.ClassParent;
  until (sS = 'TObject');
  ShowMessage(S);
end;

to drill in.  Else try this.

Share this post


Link to post
2 hours ago, Stano said:

If you place the cursor in the TButton and press F1, help will appear. And in it the whole family tree. This applies to all standard components. No more for third-party components and custom.

This is true for standard classes. But I need it for custom third-party classes.

Share this post


Link to post
5 minutes ago, PeterPanettone said:

But I need it for custom third-party classes.

Components or classes? Components will be TPersistent and they should be registered in the IDE, so more is possible with those.

The class tree will look something like this for TButton:

image.png.cbc1ab003607091c9dd6ece66ab95f35.png

4 hours ago, PeterPanettone said:

I need to get e.g. Vcl.StdCtrls.TButton from TButton. How can I do that?

You can get the defining class from the component, Marco's Object Debugger does it with the following lines using RTTI.

var
  ptd: PTypeData;
  
  //this starts at line 280 in ObjectDebuggerForm.pas
  
  // get a pointer to the TTypeData structure
  ptd := GetTypeData (pti);

  // access the TTypeInfo structure
  sList.Add ('Type Name: ' + string(pti.Name));
  sList.Add ('Type Kind: ' + GetEnumName (
    TypeInfo (TTypeKind),
    Integer (pti.Kind)));

  // access the TTypeData structure
  {omitted: the same information of pti^.Name...
  sList.Add ('ClassType: ' + ptd^.ClassType.ClassName);}
  sList.Add ('Size: ' + IntToStr (
    ptd.ClassType.InstanceSize) + ' bytes');
  sList.Add ('Defined in: ' + string(ptd.UnitName) + '.pas');

  // add the list of parent classes (if any)
  ParentClass := ptd.ClassType.ClassParent;
  if ParentClass <> nil then
  begin
    sList.Add ('');
    sList.Add ('=== Parent classes ===');
    while ParentClass <> nil do
    begin
      sList.Add (ParentClass.ClassName);
      ParentClass := ParentClass.ClassParent;
    end;
  end;

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×