[fpc-pascal] Improved FPC JSON-RPC support

Graeme Geldenhuys mailinglists at geldenhuys.co.uk
Tue Dec 28 22:22:03 CET 2021


On 2021-12-28 15:25, Michael Van Canneyt via fpc-pascal wrote:
> 
> Thanks to the magic of RTTI and Invoke(), creating a JSON-RPC server has
> just become significantly easier !

That's pretty neat - nicely done Michael.


> // Create a class that implements the interface
> Type
>    TIntf2Impl = class(TInterfacedObject, IMyOtherInterface)
>    public
>      function Echo(args: TStringArray): String;
>      function SayHello: string;
>    end;

...snip...

> // Register the class using an interface factory:
> Function GetMyOtherInterface(Const aName : string) : IInterface;
> begin
>    Result:=TIntf2Impl.Create as IInterface;
> end;


Slightly off topic, and my Object Pascal is getting a bit rusty as the 
years go by. <grin> ;-) In your factory above, is the "as IInterface" 
part needed. Can't the FPC compiler automatically cast the return type 
based on the function return type, and the fact that the compiler should 
know that TIntf2Impl type implements TInterfacedObject?


Regards,
   Graeme


More information about the fpc-pascal mailing list