John5
John5

Reputation: 13

TVirtualInterface calls the wrong invoke event

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;

Upvotes: 1

Views: 183

Answers (2)

VitaliyG
VitaliyG

Reputation: 1857

This is bug in Delphi XE3 compiler and it is fixed in XE4

Fix list for RAD Studio XE4 104613 TVirtualInterface: TRttiMethod for indexed property in interfaces

Upvotes: 2

VitaliyG
VitaliyG

Reputation: 1857

Have you tried inheriting interfaces from IInvokable and provide them with GUID like in Embarcadero example

My guess is there is some issues with interface RTTI if it is not inherited from IInvokable

Upvotes: 0

Related Questions