Creating a Struct Type

Struct types are value types and can't be accessed directly over COM in FoxPro. This means you can't simply use .CreateInstance() to create a Struct type with wwDotnetBridge.

It's still possible to create a struct type and use it, but the code is pretty ugly. The following works:

*** Parameter array for constructor (empty)
loComArray = loBridge.Createarray()  

*** Create a ComValue structure where we hold the Struct
loValue = loBridge.CreateComValue(null)

*** Create the instance and store in loValue.Value

*** To use the type - loStruct.IntValue
*** Must access double indirectly from ComValue
*** Don't reference .Value or you get error
? loBridge.GetProperty(loValue,"Value.IntValue")

This code relies on the ComValue Class in the .NET component to hold the structure as an intermediary. You can then use the .SetValueFromCreateInstance() to create the instance and reference the .Value member indirectly.

Note that .SetValueFromCreateInstance() takes a ComArray as a parameter which has to be passed even if there are no parameters so that the method signature can be found.

© West Wind Technologies, 2023 • Updated: 09/24/15
Comment or report problem with topic