Registriert seit: 12. Aug 2003
Ort: Soest
4.016 Beiträge
Delphi 10.1 Berlin Enterprise
|
AW: Lazy Initialization im Type?
19. Feb 2015, 12:56
Delphi-Quellcode:
type
UnknownObject = record
private
fInstance: IUnknownObject;
procedure EnsureInstance;
public
class operator Implicit(const value: UnknownObject): IUnknownObject;
procedure UnknownObject;
end;
procedure UnknownObject.EnsureInstance;
begin
if not Assigned(fInstance) then
fInstance := TUnknownObject.Create;
end;
class operator UnknownObject.Implicit(
const value: UnknownObject): IUnknownObject;
begin
value.EnsureInstance;
Result := value.fInstance;
end;
procedure UnknownObject.UnknownObject;
begin
EnsureInstance;
fInstance.UnknownObject
end;
|