1

I noticed a strange bug with the TVirtualInterface class. I tried something like following :

ITest1 = interface
  procedure Test1();
End;

ITest2 = Interface(ITest1)
  procedure Test2();
End;

ITest3 = Interface(ITest2)
  procedure Test3();
ENd;

procedure Test();
var 
    test : ITest3;
begin
    test := TVirtualInterface(TypeInfo(ITest3),
        procedure(Method: TRttiMethod;
            const Args: TArray<TValue>; out Result: TValue)
        begin
            showMessage(Method.Name);
        end) as ITest3;

    test.test1();
    test.test2();
    test.test3();
End;

The code above works fine. If i change it like this :

ITest3 = Interface(ITest2)
  procedure Test3();
  function GetLabel : string;
  property Label : string read GetLabel;
ENd;

and i call :

showmessage(test.Label);

... it still works.

But if i move this property to ITest2 or ITest1, calls to some methods of any of ITest1, ITest2 or ITest3 will either call the wrong method (for example test.Test2() will display "Test3"), either crash (access violation).

Any explanation and/or fix to this ?

Edit >> Sorry, actually it actually seems to fail only with properties of the kind :

property Item[Name : string] : X read GetX write SetX;
4

2 回答 2

2

这是 Delphi XE3 编译器中的错误,在 XE4 中已修复

RAD Studio XE4 104613 TVirtualInterface 的修复列表:接口中索引属性的 TRttiMethod

于 2013-08-28T11:51:29.340 回答
0

您是否尝试过从Embarcadero示例IInvokable中继承接口并为其提供 GUID

我的猜测是接口 RTTI 存在一些问题,如果它不是继承自IInvokable

于 2013-08-27T18:49:28.210 回答