ancestry,component,ClassType,ClassParent,delphi

Omar 10/12/2016 0

This example shows how to obtain the ancestry of a component using the ClassType and ClassParent properties. It uses a button and a list box on a form. When you click the button, the name of the button's class and the names of its parent classes are added to the list box.

Delphi
 procedure TForm1.Button1Click(Sender: TObject);
var
  ClassRef: TClass;
begin
  ListBox1.Clear;
  ClassRef := Sender.ClassType;
  while ClassRef <> nil do
  begin
    ListBox1.Items.Add(ClassRef.ClassName);
    ClassRef := ClassRef.ClassParent;
  end;
end;
{
The list box contains the following strings after you click the button:
	TButton
	TButtonControl
	TWinControl or TWinControl
	TControl
	TComponent
	TPersistent
	TObject 
} 

Report Bug

Please Login to Report Bug

Reported Bugs

Comments

Please Login to Comment

Comments