Is it possible to achieve this dynamically without resorting to type casting? It feels like classes should have a builtin type for each class, like TClassType, which similar to TObject.ClassType but is a compile time type.
=========
{$mode objfpc}
program test;
type
TBase = class
// TClassType should be the type of the current class
private type TClassType = ...;
public
function AndThis: TBase;
end;
function TBase.AndThis: TBase;
begin
result := self;
end;
type
TMyClass = class (TBase)
end;
var
c: TMyClass;
begin
// error: Incompatible types: got "TBase" expected "TMyClass"
c := TMyClass.Create.AndThis;
writeln(c.classname);
end.Regards,
Ryan Joseph
