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)
Parameters
typeName
Name of the type to instantiate
parms
This is an instance of the .NET ComArray instance. Note this parameter has to be passed even if you have no parameters - just pass an empty instance.
Example
loBridge = GetwwDotnetBridge()
loBridge.LoadAssembly([System.Drawing])
*** This doesn't work because Rectangle is a Value type
*** that can't be accessed directly in VFP
*oRect = loBridge.CreateInstance([System.Drawing.Rectangle],10,10,20,30)
*** Create COM Value structure to hold the Rectangle
loRectangle = loBridge.CreateComValue()
*** This type has no parameterless constructors
*** so we need a ComArray for the arguments
*** NOTE: Always create and pass parameter array even for no parms
loParms = loBridge.CreateArray("System.Int32")
*** Add the parameters
loParms.AddItem(10)
loParms.AddItem(10)
loParms.AddItem(20)
loParms.AddItem(30)
*** Now create the instance and set on the ComValue object
loRectangle.SetValueFromCreateInstance("System.Drawing.Rectangle",loParms)
*** The Value is a .NET Value type which can't be accessed in VFP
* ? loRectangle.Value.Width && fails
*** Use double indirect access instead
? loBridge.GetPropertyEx(loRectangle,"Value.Width")
See also:
Class ComValue© West Wind Technologies, 2023 • Updated: 09/24/15
Comment or report problem with topic