Quantcast
Channel: Delphi – The Wiert Corner – irregular stream of stuff
Viewing all articles
Browse latest Browse all 1440

Delphi: TInvokableClassRegistryHelper.GetInterfaceNamespace as the opposite of TInvokableClassRegistry.RegisterInterface

$
0
0

A while ago, I needed the opposite of InvRegistry.RegisterInterface(TypeInfo(MySoapInterfacePortType, 'urn:myURN', 'utf-8');, so instead of registering an interface with a namespace URN, obtain the URN by passing the interface inverting [WayBack] TInvokableClassRegistry.RegisterInterface.

This is the class helper I wrote:

type
  TInvokableClassRegistryHelper = class helper for TInvokableClassRegistry
  public
    function GetInterfaceNamespace(Info: PTypeInfo): string;
  end;

function TInvokableClassRegistryHelper.GetInterfaceNamespace(Info: PTypeInfo): string;
var
  InfoGuid: TGUID;
begin
  // call like `Result := InvRegistry.GetInterfaceNamespace(TypeInfo(MySoapInterfaceType));`
  InfoGuid := GetTypeData(Info)^.Guid; // uses TypInfo; see https://stackoverflow.com/questions/8439246/is-it-possible-to-get-the-value-of-a-guid-on-an-interface-using-rtti
  Result := GetNamespaceByGUID(InfoGuid);
end;

It would have been a lot easier if TInvokableClassRegistry.GetIntfIndex has been public, because then [WayBack]TInvokableClassRegistry.GetRegInterfaceEntry could have been used.

–jeroen


Viewing all articles
Browse latest Browse all 1440

Trending Articles