Class ComValue

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.

Simple type conversion:

*** Create .NET Object instance
loNet = loBridge.CreateInstance("MyApp.MyNetObject")

*** Convert the 'unsupported' parameter type
LOCAL loVal as Westwind.WebConnection.ComValue
loVal = loBridge.CreateComValue()
loVal.SetInt16(11)

*** Call method that takes Int16 parameter
loBridge.InvokeMethod(loNet,"PassInt16",loVal)

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.

System.Object
  Westwind.WebConnection.ComValue
public class ComValue : object

Class Members

MemberDescription

Constructor

GetGuid

Returns a GUID stored in the Value properties.

o.ComValue.GetGuid()

GetTypeName

o.ComValue.GetTypeName()

GetValue

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

o.ComValue.GetValue()

NewGuid

Creates a new GUID and stores it in the Value.

o.NewGuid()

SetByte

Returns a byte value which is similar to Int16.

public void SetByte(object value);

SetChar

Converts a FoxPro string or number to a .NET char value on the Value structure.

o.ComValue.SetChar(object val)

SetDbNull

Sets a DbNull value from FoxPro. DbNull is a value type and can't be accessed directly in FoxPro.

o.ComValue.SetDbNull()

SetDecimal

Sets a Decimal value. Turns any FoxPro numeric value to a .NET decimal value.

This can actually be done in FoxPro explicitly with CAST(val as Currency) but this method can be used with pre-VFP 9 and is used internally to convert numerics to decimal.

public void SetDecimal(object val);

SetEnum

Allows you to create an Enum value that can be passed as a parameter.

o.ComValue.SetEnum(string enumString)

SetGuid

Sets the value to a .NET Guid by passing in either a GUID string, a ComGuid object, or a null (which creates a new Guid).

o.ComValue.SetGuid(object value)

SetInt16

Sets a Short value which is not supported in Visual FoxPro

public void SetInt16(object val);

SetInt64

Sets a Int64 value from a FoxPro numeric value. Since FoxPro doesn't have a cast to 64 bit values natively you can use decimal or float values in Fox or 32 bit integers.

public void SetInt64(object val);

SetLong

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.

public void SetLong(object val);

SetSingle

Sets the value of this object to a Single based on a FoxPro number passed in.

o.ComValue.SetSingle(lnValue)

SetSingle

Sets the value of this object to a .NET Single/float based on a FoxPro number passed in.

o.SetFloat(lnValue)

SetUInt32

Sets a 32 bit UInt value on the Value property.

o.ComValue.SetUInt34(object val)

SetUInt64

Sets a 64 bit unsigned integer value from a FoxPro number.

o.ComValue.SetUInt64(object val)

SetValueFromCreateGenericInstance

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

o.ComValue.SetValueFromCreateGenericInstance(lcGenericType,loTypes,loParms)

SetValueFromCreateInstance

Allows setting of the Value property from the result of an object instantiation.

Useful when instantiating types that can't be accessed in VFP such as Generic types or Value types. Using this mechanism you can create an instance of the type.

o.ComValue.SetValueFromCreateInstance(string typeName,ComArray parms)

SetValueFromEnum

o.ComValue.SetValueFromEnum(string enumType, string enumKeyName)

SetValueFromInvokeMethod

Sets the Value property from a method call that passes it's positional arguments as an array.

Note that the array of parameters must be passed in as a COM Array.

public void SetValueFromInvokeMethod(object objectRef,     string method,     ComArray parms);

SetValueFromInvokeStaticMethod

Sets the Value property from a method call that passes it's positional arguments as an array.

Note that the array of parameters must be passed in as a COM Array.

public void SetValueFromInvokeMethod(string typename,     string method,     ComArray parms);

SetValueFromProperty

Sets the Value property from a property retrieved from .NET Useful to transfer value in .NET that are marshalled incorrectly in FoxPro such as Enum values (that are marshalled as numbers).

public void SetValueFromProperty(object objectRef,     string property);

SetValueFromStaticProperty

Sets the value property from a static property retrieved from .NET. Useful to transfer value in .NET that are marshalled incorrectly in FoxPro such as Enum values (that are marshalled as numbers)

public void SetValueFromStaticProperty(string typeName,     string property);

SetValueFromSystemConvert

o.ComValue.SetValueFromSystemConvert(string method, object value)

ToString

Returns the value of contained ComValue instance value as a string.

Same as loComValue.Value.ToString() but doesn't require the implicit InvokeMethod() call.

o.ComValue.ToString()

Value

Internally this value is set by the various SetXXX methods. It's of type objcect but set to the appropriate .NET subtype.

Requirements

Namespace: Westwind.WebConnection
Assembly: wwdotnetbridge.dll

© West Wind Technologies, 1996-2019 • Updated: 12/23/15
Comment or report problem with topic