In a 32-bit VCL Application in Windows 10 in Delphi 11 Alexandria, I am trying to write a small app that finds the list of ANCESTORS from a class name that the user inputs in an Edit box:
procedure TForm1.DoShowAncestors(const aClassName: string);
var
ClassRef: TClass;
begin
lstAncestors.Clear;
// Does not work:
//ClassRef := TClass.Create;
//ClassRef.ClassName := aClassName;
// [dcc32 Error] E2076 This form of method call only allowed for class methods or constructor:
ClassRef := TClass(aClassName).ClassType;
while ClassRef <> nil do
begin
lstAncestors.Items.Add(ClassRef.ClassName);
ClassRef := ClassRef.ClassParent;
end;
end;
procedure TForm1.edtClassNameKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if Key = VK_RETURN then
begin
DoShowAncestors(Trim(edtClassName.Text));
end;
end;
However, the problem is to transform the input string into a TClass object. See the above error comments.
