[fpc-pascal] Improved FPC JSON-RPC support

Michael Van Canneyt michael at freepascal.org
Tue Dec 28 23:11:42 CET 2021



On Tue, 28 Dec 2021, Graeme Geldenhuys via fpc-pascal wrote:

> 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.

We do our best.

>> // 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?

No, theoretically it probably could, but type inference is not implemented in Pascal.

Michael.


More information about the fpc-pascal mailing list