Creates an instance of a ComValue object which allows you to capture values from method calls and properties and keep them in .NET.
Use for Problem Types
Use this object to pass problem types that don't translate between FoxPro and .NET (arrays, NULLS, Structs etc.)
Use for Reference Parameters
If you need to pass parameters to a function byRef
, you can use ComValue to pass the parameter. Simply create a ComValue object and assign the value. Any call to InvokeMethod()
(or one of its variants) that receives a ComValue object parameter stores that parameter and reassigns it after the method call. If the value changes the ComValue() object then holds the changed value on return of the method call.
o.CreateComValue(lvValue)
Parameters
lvValue
Optional - value to assign to the Value property
The values are assigned to the .Value
property using .SetProperty()
which means that values are 'normalized' to .NET types. If you pass a ComArray the ComArray is turned into a plain .NET array, Null values are turned into DbNull.Value, Guids are turned from strings to Guid objects etc.
Example
*** Simple Method Invokation:
loNet = loBridge.Createinstance("Westwind.WebConnection.TypePassingTests")
loInt = loBridge.CreateComValue(INT(10))
loString = loBridge.CreateComValue("Hello World.")
loDecimal = loBridge.CreateComValue(CAST( 5.22 as Currency))
loLong = loBridge.CreateComValue()
loLong.SetLong(10) && Longs are not natively supported in FoxPro
lobridge.InvokeMethod(loNet,;
"PassByReference",;
loInt,loString,loDecimal,loLong)
*** ByRef vars are updated
? "Updated:"
? loInt.Value, loString.Value, loDecimal.Value, loLong.Value
*** Create an array of parameters
loParms = loBridge.CreateArray("System.Object")
loParms.AddItem(objLogin)
? loParms.Count
*** Create a COM Value structure
LOCAL loValue as Westwind.WebConnection.ComValue
loValue = loBridge.CreateComValue()
*** Invoke a method and set the value from the method result
loValue.SetValueFromInvokeMethod(loProxy.oSERVICE,"IsAliveDB",loParms)
*** Example of calling a method with an array by reference
loStrings = loBridge.CreateArray("System.String")
loStrings.AddItem("It's")
loStrings.AddItem("BigDay")
*** Assign to value structure so we can pass by reference
loValue = loBridge.CreateComValue(loStrings)
*** pass the value as a 'byref' parameter
lobridge.InvokeMethod(loNet,"PassArrayByReference",loValue)
*** pick up the result value
loStringsResult = loBridge.GetProperty(loValue,"Value")
* loStringsResult = loValue.GetValue() && normalized value - in future versions
? loStringsResult.Count && 7
See also:
Class wwDotNetBridge© West Wind Technologies, 1996-2024 • Updated: 05/05/16
Comment or report problem with topic