Anonymous recursions

This commit is contained in:
Michael Schimmel
2025-09-19 23:53:48 +02:00
parent 28558614f0
commit e03155179a
7 changed files with 126 additions and 49 deletions
+45
View File
@@ -0,0 +1,45 @@
unit Myc.Utils;
interface
type
TManaged<T: class> = record
private
type
TObj = class(TInterfacedObject)
FValue: T;
constructor Create(AValue: T);
destructor Destroy; override;
end;
var
FIntf: IInterface;
public
class operator Implicit(A: T): TManaged<T>; overload;
class operator Implicit(const Upvalue: TManaged<T>): T; overload;
end;
implementation
constructor TManaged<T>.TObj.Create(AValue: T);
begin
inherited Create;
FValue := AValue;
end;
destructor TManaged<T>.TObj.Destroy;
begin
FValue.Free;
inherited;
end;
class operator TManaged<T>.Implicit(A: T): TManaged<T>;
begin
Result.FIntf := TObj.Create(A);
end;
class operator TManaged<T>.Implicit(const Upvalue: TManaged<T>): T;
begin
Result := (Upvalue.FIntf as TObj).FValue;
end;
end.