Code Monkey home page Code Monkey logo

Comments (3)

staticcat avatar staticcat commented on August 28, 2024

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.

The 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.

from delphi-mocks.

rpottsoh avatar rpottsoh commented on August 28, 2024

Thanks for the reply. Doesn't sound like any small undertaking to achieve this capability. My best bet would probably be to eliminate my argument passed by reference and have my method just return the data instead; pass the old result value of the method through a separate property/method.

Sent from my android device.

-----Original Message-----
From: Jason Smith [email protected]
To: VSoftTechnologies/Delphi-Mocks [email protected]
Cc: Ryan Potts [email protected]
Sent: Tue, 29 Mar 2016 7:32 PM
Subject: Re: [VSoftTechnologies/Delphi-Mocks] Question: How to mock a method that passes a parameter by reference? (#88)

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.

The 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.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
#88 (comment)

from delphi-mocks.

staticcat avatar staticcat commented on August 28, 2024

Yes, and it is one of the draw backs for using Delphi.Mocks. Even in C# you have to do something like the following for Moq.

int outVariable = 2;
myMock.Setup(x => x.FuncWithOutVar(out outVariable)).Returns(true);

The outVariable always gets a hint saying it could be removed as the value is not used. I suspect we would get the same thing in delphi as the compiler has no idea we are intercepting the method call.

from delphi-mocks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.