{"action":"created","issue":{"url":"https://api.github.com/repos/VSoftTechnologies/Delphi-Mocks/issues/88","repository_url":"https://api.github.com/repos/VSoftTechnologies/Delphi-Mocks","labels_url":"https://api.github.com/repos/VSoftTechnologies/Delphi-Mocks/issues/88/labels{/name}","comments_url":"https://api.github.com/repos/VSoftTechnologies/Delphi-Mocks/issues/88/comments","events_url":"https://api.github.com/repos/VSoftTechnologies/Delphi-Mocks/issues/88/events","html_url":"https://github.com/VSoftTechnologies/Delphi-Mocks/issues/88","id":144334945,"number":88,"title":"Question: How to mock a method that passes a parameter by reference?","user":{"login":"rpottsoh","id":6978003,"avatar_url":"https://avatars.githubusercontent.com/u/6978003?v=3","gravatar_id":"","url":"https://api.github.com/users/rpottsoh","html_url":"https://github.com/rpottsoh","followers_url":"https://api.github.com/users/rpottsoh/followers","following_url":"https://api.github.com/users/rpottsoh/following{/other_user}","gists_url":"https://api.github.com/users/rpottsoh/gists{/gist_id}","starred_url":"https://api.github.com/users/rpottsoh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rpottsoh/subscriptions","organizations_url":"https://api.github.com/users/rpottsoh/orgs","repos_url":"https://api.github.com/users/rpottsoh/repos","events_url":"https://api.github.com/users/rpottsoh/events{/privacy}","received_events_url":"https://api.github.com/users/rpottsoh/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-29T17:35:26Z","updated_at":"2016-03-29T23:32:11Z","closed_at":null,"body":"I have a method (function) that has two arguments and returns an integer.  The first argument is passed by value and the second by reference (var).  I would like to mock what this method should pass back on on the second argument.  First, the closest thing I can see to accomplish this is to use WillExecute.  However this only passes my method's arguments in as const.  I am setting the result of my TExecuteFunc equal to args[0].  I would like to set args[1] equal to some value.\r\n\r\nHow to mock, or stub, a method that has one or more arguments that are passed by reference?  I am wanting to test the argument that is passed by reference.  The CUT has a method that that passes an argument by reference.\r\n\r\n`    MockDap.Setup.WillExecute(function (const args : TArray<TValue>; const ReturnType : TRttiType) : TValue\r\n                              begin\r\n                                result := args[0];\r\n                                args[1] := Expected;\r\n                              end).When.GetDAPData(TheLength, Actual);\r\n`\r\n\r\nThanks"},"comment":{"url":"https://api.github.com/repos/VSoftTechnologies/Delphi-Mocks/issues/comments/203158166","html_url":"https://github.com/VSoftTechnologies/Delphi-Mocks/issues/88#issuecomment-203158166","issue_url":"https://api.github.com/repos/VSoftTechnologies/Delphi-Mocks/issues/88","id":203158166,"user":{"login":"staticcat","id":2058893,"avatar_url":"https://avatars.githubusercontent.com/u/2058893?v=3","gravatar_id":"","url":"https://api.github.com/users/staticcat","html_url":"https://github.com/staticcat","followers_url":"https://api.github.com/users/staticcat/followers","following_url":"https://api.github.com/users/staticcat/following{/other_user}","gists_url":"https://api.github.com/users/staticcat/gists{/gist_id}","starred_url":"https://api.github.com/users/staticcat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/staticcat/subscriptions","organizations_url":"https://api.github.com/users/staticcat/orgs","repos_url":"https://api.github.com/users/staticcat/repos","events_url":"https://api.github.com/users/staticcat/events{/privacy}","received_events_url":"https://api.github.com/users/staticcat/received_events","type":"User","site_admin":false},"created_at":"2016-03-29T23:32:11Z","updated_at":"2016-03-29T23:32:11Z","body":"Currently there isn't a way to achieve var or out parameter return values with Delphi.Mocks. I have had plans on how to achieve this, just haven't had the time to attempt its implementation. \r\n\r\nThe DoInvoke of the proxy classes needs to handle updating var variables and out variables. Even though the args array is const itself, from memory the values of the variables at each index could be altered to the desired values. These would then be returned to the caller, only when the value was either listed as var, or out. If there is information on the method as to the parameter type we could even protect against this. "}}