ComValue allows you to create .NET objects that can be passed to indirectly called wwDotnetBridge methods via SetProperty, InvokeMethod, CreateInstance and ComArray.AddItem. Use ComValue when the type that needs to be passed or assigned is of a type that cannot be marshalled through FoxPro, or to assign/pass types that have are not directly supported by the FoxPro type system. You can also use these when you get .NET overload mapping errors (Method or Constructor not found) when the COM type conversions won't uniquely identify a .NET signature.

Examples of unsupported types are Long, Single, Decimal, Guid, Byte, DbNull and Char and Value types that need to be passed by parameter. Examples of values that might not map are Enums, Value types and Generic types.

How it works

ComValue works by creating an object inside of .NET and assigning a value on this object through the various access methods that can perform the proper type translations from the FoxPro value. Then, rather than passing the real value, using indirect methods you can pass the ComValue object in place of the questionable parameter. wwDotnetBridge then fixes up the parameter and passes the actual .NET value as a parameter to the method parameter or property value.

ComValue objects must be used with one of the following wwDotnetBridge methods to assign a value:

SetProperty/SetPropertyEx()

InvokeMethod()

CreateInstance() (constructors with parameters)

ComArray.AddItem()

You can't pass ComValue() to .NET methods directly, because they'll have no idea what the COM value represents. wwDotnetBridge performs special processing on the ComValue instance by extracting the value and then assigning it to the parameter or property at runtime.

Using ComValue allows you to keep a value inside of .NET without ever passing the actual value to FoxPro. This makes it possible to work with types that COM and FoxPro don't support as well providing exactly typed values to assign in method overloads.

ComValue caching for Method and Property Invocation

This class also supports setting a ComValue from properties and method results. This is useful if you have a method or property that uses a type inaccessible via COM (like strongly typed or subclassed dataset objects for example). In this case you can call the SetValueXXX methods to fill the ComValue structure and then use this ComValue in InvokeMethod, SetProperty calls which automatically pick up this ComValue object's underlying .NET type.

*** Create an array of parameters (ComArray instance)
loParms = loBridge.CreateArray("System.Object")
loParms.AddItem("Username")
loParms.AddItem("Password")
loParms.AddItem("Error Message")
*** Create a ComValue structure to hold the result: a DataSet
LOCAL loValue as Westwind.WebConnection.ComValue
loValue = loBridge.CreateComValue()
*** Invoke the method and store the result on the ComValue structure
*** Result from this method is DataSet which can't be marshalled properly over COM
? loValue.SetValueFromInvokeMethod(loService,"Login",loParms)
*** This is your raw DataSet
*? loValue.Value && direct access won't work because it won't marshal
*** Now call a method that requires the DataSet parameter
loBridge.InvokeMethod(loService,"AcceptDataSet",loValue)

The jist of this is that the DataSet result is never passed through FoxPro code, but is stored in ComValue and then that ComValue is used as a parameter in the InvokeMethod call. All indirect execution methods (InvokeMethod,SetProperty etc.) understand ComValue and use the Value property for the parameter provided.

Class Members

Retrieves the fixed up value from the .Value property. The call is returned by calling .GetProperty() to retrieve the value which automatically converts problem types to the appropriate wrapper types (ie. Array/Collections to ComArrays, DbNulls to Nulls etc.).

Turns a FoxPro number to a Long 64 bit integer value in .NET. Note that FoxPro doesn't support casting to a 64 bit value, so you can pass a 32 bit integer or numbers that are decimal or floats to this function to achieve 64 bit Long values.

This method creates an instance of a generic type on the ComValue structure by allowing you to specify a generic type name, the generic type parameters (as a ComArray) and optional constructor parameters (as a ComArray.)