VSoftTechnologies/Delphi-Mocks — pull request #27 by fabriciocolombo (2014-04-02 03:08:42+00:00)
Title: Included instance as first argument because TExpectation.Match deduces t...

...hat the first argument is the object instance.

The method TExpectation.Match believes that the first argument of the array is the instance of the target object,

if Length(Args) <> (Length(FArgs) + 1 ) then
exit;
//start at 1 as we don't care about matching the first arg (self)
for i := 1 to Length(args) -1 do

but the implementation of TVirtualInterface and TVirtualMethodInterceptor are different.

TVirtualInterface.OnInvoke = procedure(Method: TRttiMethod; const Args: TArray; out Result: TValue)
TVirtualMethodInterceptor.OnBefore = procedure(Instance: TObject; Method: TRttiMethod; const Args: TArray; out DoInvoke: Boolean; out Result: TValue)

TVirtualInterface passes the instance of the object (Self) as the first argument of Args, but TVirtualMethodInterceptor passes the instance as a separate argument, causing trouble in the Match method.

Perhaps there is a better way to implement this solution. I'm open to suggestions.