From 67065d7bf8405ccc38d911b928c88a64d79902c6 Mon Sep 17 00:00:00 2001 From: Jens Geyer Date: Sat, 6 Jul 2013 14:28:43 +0200 Subject: [PATCH] THRIFT-2084 Delphi: Ability to create entity Thrift-generated instances based on TypeInfo Patch: Jens Geyer --- lib/delphi/src/Thrift.TypeRegistry.pas | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/delphi/src/Thrift.TypeRegistry.pas b/lib/delphi/src/Thrift.TypeRegistry.pas index 1b863d2e..cc22952a 100644 --- a/lib/delphi/src/Thrift.TypeRegistry.pas +++ b/lib/delphi/src/Thrift.TypeRegistry.pas @@ -22,7 +22,8 @@ unit Thrift.TypeRegistry; interface uses - Generics.Collections; + Generics.Collections, TypInfo, + Thrift.Protocol; type TFactoryMethod = function:T; @@ -35,12 +36,11 @@ type class destructor Destroy; class procedure RegisterTypeFactory(const aFactoryMethod: TFactoryMethod); class function Construct: F; + class function ConstructFromTypeInfo(const aTypeInfo: PTypeInfo): IBase; end; implementation -uses - TypInfo; { TypeRegistration } @@ -80,5 +80,16 @@ begin 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(Factory)()); +end; + + + end. -- 2.17.1