Type Casting Numbers to match .NET Types
When calling methods or setting properties on numeric members in .NET objects you have to ensure that the data type passed matches the .NET numeric type or the call to COM object will fail due to type translation.
For example, if you're calling a method that looks like this:
public decimal Add(decimal val1, decimal val2) {}
you have to explicitly cast the FoxPro number to Currency:
loBridge.InvokeMethod(loInstance, CAST(11.22 as Currency),CAST(21.12 as Currency)
The default FoxPro numeric type is Float or Double and if .NET functions expect integers, decimals or single values you have to cast appropriately.
.NET Type | FoxPro Type |
---|---|
Int,Int32 | Integer |
Long,Int64 | not supported (see below) |
Decimal | Currency |
Float | Double, Float |
Single | Numeric or Double |
byte[] | Blob,VarBinary |
Special Handling of .NET Long Values
Long is a non-supported COM and FoxPro type so it cannot be passed over COM directly in direct access of properties or as parameter or result values from .NET methods. In order to use it you have to go the wwDotnetBridge's helper functions which convert the value into an decimal.
For reading Long properties or capturing a Long return type you can use either GetProperty()
or InvokeMethod()
, which will automatically convert the value to a FoxPro number.
* loInstance.GetLongResult()
lnLongValue = loBridge.InvokeMethod(loInstance,"GetLongResult")
* loInstance.LongValue
lnLongValue = loBridge.GetProperty(loInstance,"LongValue")
For passing a Long value to .NET you have to use the ComValue
structure.
loLong = loBridge.CreateComValue()
loLong.SetLong(10)
loBridge.InvokeMethod(loInstance,"PassLongParameter",loLong)
loBridge.SetProperty(loInstance,"LongValue", loLong)
© West Wind Technologies, 2004-2020 • Updated: 03/11/19
Comment or report problem with topic