THRIFT-2084  Delphi: Ability to create entity Thrift-generated instances based on TypeInfo

Patch: Jens Geyer
diff --git a/lib/delphi/src/Thrift.TypeRegistry.pas b/lib/delphi/src/Thrift.TypeRegistry.pas
index 1b863d2..cc22952 100644
--- a/lib/delphi/src/Thrift.TypeRegistry.pas
+++ b/lib/delphi/src/Thrift.TypeRegistry.pas
@@ -22,7 +22,8 @@
 interface

 

 uses

-  Generics.Collections;

+  Generics.Collections, TypInfo,

+  Thrift.Protocol;

 

 type

   TFactoryMethod<T> = function:T;

@@ -35,12 +36,11 @@
     class destructor Destroy;

     class procedure RegisterTypeFactory<F>(const aFactoryMethod: TFactoryMethod<F>);

     class function  Construct<F>: F;

+    class function  ConstructFromTypeInfo(const aTypeInfo: PTypeInfo): IBase;

   end;

 

 implementation

 

-uses

-  TypInfo;

 

 { TypeRegistration }

 

@@ -80,5 +80,16 @@
   end;

 end;

 

+class function TypeRegistry.ConstructFromTypeInfo(const aTypeInfo: PTypeInfo): IBase;

+var

+  Factory      : Pointer;

+begin

+  Result := nil;

+  if FTypeInfoToFactoryLookup.TryGetValue(aTypeInfo, Factory)

+  then Result := IBase(TFactoryMethod<IBase>(Factory)());

+end;

+

+

+

 

 end.