#1 2023-02-24 15:53:55

rdevine
Member
Registered: 2014-02-20
Posts: 52

Interface enumerated return type

If I declare an interface service method with an enumerated return type which has the values specified, then I get an AV in TInterfaceFactory.Create at AddMethodsFromTypeInfo(aInterface). I guess this is from the lack of RTTI in Delphi enums with specified values. Not a problem for me but would be good to raise a specific exception. Using Delphi 11.2 and the latest pull of mORMot2.

Cheers, Bob

Offline

#2 2023-02-24 17:16:23

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,706
Website

Re: Interface enumerated return type

I use interface services with regular enumerate types as function result with no issue.

But of course, the framework needs RTTI.
So we indeed need regular enums with no forced values - what I call "regular" enumerate types.

Offline

#3 2023-02-24 17:19:18

rdevine
Member
Registered: 2014-02-20
Posts: 52

Re: Interface enumerated return type

It happens in the case of enumerated return type where the values are explicitly specified, e.g. TTestEnum = (enum1 = 1, enum2 = 2,...).

(Just saw your edited reply :-)) I realise there's no way round it - just it would be helpful to have an exception message.

Cheers, Bob

Last edited by rdevine (2023-02-24 17:20:37)

Offline

#4 2023-02-25 09:34:04

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,706
Website

Re: Interface enumerated return type

Does the following do what you expect?

https://github.com/synopse/mORMot2/commit/ab007691

Offline

#5 2023-02-25 10:00:58

rdevine
Member
Registered: 2014-02-20
Posts: 52

Re: Interface enumerated return type

Still getting a generic AV message (I can see the new exception in the code as I step through but it doesn't get there). For testing I'm using a VCL forms app with the following simple code in the form unit:

  TTestEnum = (tteOne = 1,
               tteTwo = 2);

  ITestIntf = interface(IInvokable)
    ['{7F2B6047-D04B-488E-AA6D-03E184BE980A}']
    function TestEnum: TTestEnum;
  end;
  ....
  initialization
    TInterfaceFactory.RegisterInterfaces([TypeInfo(ITestIntf)]);

Offline

Board footer

Powered by FluxBB