Looks like a bug in TVirtualInterface in Linux.

Looks like a bug in TVirtualInterface in Linux. I wonder if experts here would have a clue about why this is happening and if there is a workaround? The problem only happens with some return values (double, single and currency). The following test code will output "13" for all calls in Win32, but will return wrong in Linux.

program TestVirtualInterface;

{$APPTYPE CONSOLE}

uses
System.SysUtils, System.Rtti;

type
IMath = interface(IInvokable)
['{BAD477A2-86EC-45B9-A1B1-C896C58DD5E0}']
function ValueDouble: Double;
function ValueCurrency: Currency;
function ValueSingle: Single;
function ValueExtended: Extended;
function ValueInteger: Integer;
function ValueInt64: Int64;
function ValueByte: Byte;
function ValueSmallInt: SmallInt;
procedure GetValueDouble(var D: Double);
end;

procedure Run;
var
V: TVirtualInterface;
M: IMath;
D: Double;
begin
V := TVirtualInterface.Create(TypeInfo(IMath));
V.OnInvoke := procedure(Method: TRttiMethod;
const Args: TArray; out Result: TValue)
begin
if Length(Args) > 1 then
Args[1] := 13
else
Result := 13;
end;
V.QueryInterface(IMath, M);
WriteLn('ValueDouble: ' + FloatToStr(M.ValueDouble));
WriteLn('ValueCurrency: ' + FloatToStr(M.ValueCurrency));
WriteLn('ValueSingle: ' + FloatToStr(M.ValueSingle));
WriteLn('ValueExtended: ' + FloatToStr(M.ValueExtended));
WriteLn('ValueInteger: ' + FloatToStr(M.ValueInteger));
WriteLn('ValueInt64: ' + FloatToStr(M.ValueInt64));
WriteLn('ValueByte: ' + FloatToStr(M.ValueByte));
WriteLn('ValueSmallInt: ' + FloatToStr(M.ValueSmallInt));

D := 1;
M.getValueDouble(D);
WriteLn('GetValueDouble: ' + FloatToStr(D));
end;

begin
Run;
ReadLn;
end.

Linux Output:
ValueDouble: 0
ValueCurrency: 14073255710.592
ValueSingle: 2.99647525871033E32
ValueExtended: 13
ValueInteger: 13
ValueInt64: 13
ValueByte: 13
ValueSmallInt: 13
GetValueDouble: 13

QC Open: RSP-17856

Comments