From: Jens Geyer Date: Sat, 6 Jul 2013 12:28:43 +0000 (+0200) Subject: THRIFT-2084 Delphi: Ability to create entity Thrift-generated instances based on... X-Git-Tag: 0.9.1~42 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=67065d7bf8405ccc38d911b928c88a64d79902c6;p=common%2Fthrift.git 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 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.