#1 2020-11-29 23:59:57

radexpol
Member
From: Poland, Krk
Registered: 2019-11-29
Posts: 116

Record too small

---------------------------
Debugger Exception Notification
---------------------------
Project RestProtocol.exe raised exception class EInterfaceFactoryException with message 'TInterfaceFactoryRTTI.Create: TCounters record too small in IServerMonitor.PerformanceCounters method Items parameter'.
---------------------------
Break   Continue   Help   
---------------------------

type
  TCounters = record
    MemoryUsage: Integer;
    ThreadsCount: integer;
  end;

  IServerMonitor = interface(IInvokable)
    ['{592BF05B-ACA3-434B-8675-B2B498E7DD2D}']
    function PerformanceCounters(out Items: TCounters): TResponse;
  end;

implementation

initialization
  TInterfaceFactory.RegisterInterfaces([TypeInfo(IServerMonitor)]);

end.

Whats am I doing wrong?

Offline

#2 2020-11-30 09:05:57

radexpol
Member
From: Poland, Krk
Registered: 2019-11-29
Posts: 116

Re: Record too small

I've added fake field to record

type
  TCounters = record
    MemoryUsage: Integer;
    ThreadsCount: integer;
    fake: string;
  end;

and it worked.

Strange behavior.

Offline

#3 2020-11-30 10:44:21

Vitaly
Member
From: UAE
Registered: 2017-01-31
Posts: 168
Website

Re: Record too small

I guess, the problem was that your first record didn't contain any managed type field: https://synopse.info/forum/viewtopic.ph … 223#p31223

Offline

#4 2020-11-30 13:32:13

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

Re: Record too small

Yes, this is a compiler limitation.

The easiest workaround is to define two out parameters, MemoryUsage and ThreadsCount.

If you really want to have the JSON with two fields, then use a variant field, and manual _ObjFast() serialization.

Offline

Board footer

Powered by FluxBB