What is the use of the runtime implementation interface?

I am trying to understand the TVirtualInterface class.

{$APPTYPE CONSOLE} uses SysUtils, Rtti; type ISpecificInterface = interface(IInvokable) ['{281D8B97-397E-430A-895A-9CA4E1F5FB5F}'] procedure SpecificProcedure; end; procedure AProcedure(Method: TRttiMethod; const Args: TArray<TValue>; out Result: TValue); begin Writeln(Method.ToString); end; var ISpecificInterfaceInstance: ISpecificInterface; begin ISpecificInterfaceInstance := TVirtualInterface.Create (TypeInfo(ISpecificInterface), AProcedure) as ISpecificInterface; ISpecificInterfaceInstance.SpecificProcedure; end. // TVirtualInterface ref. counter is decremented 

What is the advantage of implementing an interface at runtime?

What is the use of space?

+6
source share
2 answers

Description here

Provides functions for marshaling a remote procedure call ...

+5
source

There are many ways to use this, but they all have common similarities because, because you use the interface, the subscriber side does not care what the implementation looks like - if it is the actual class that implemented the interface in compiletime or if you dynamically implemented it at run time through TVirtualInterface or in other ways if it behaves in accordance with the interface contract.

When it was first introduced in XE2, I wrote an article about it and its possible uses. As mentioned in the comments, it actually allowed us to implement mocking frameworks very simply by simply declaring the common types of layouts that internally create an interface proxy that handles the calls specified in the layout.

+4
source

All Articles