Now that I realize 'long' stands for 'long int', I've succeeded in
writing conversion routines for the Currency and Decimal types. They
work with everything I've thrown at them, including the highest value
that the Decimal type can handle. But I have a possible problem.
First, here are the DecimalPlugin.cpp routines:
static REALobject convertCurrToDec(long long x)
{
REALobject z;
DecData *zData;
z = REALnewInstance("Decimal");
zData = (DecData *) REALGetClassData(z, &DecClass);
getDec_Curr(*zData, x);
return z;
}/* convertCurrToDec */
static long long convertDecToCurr(REALobject x)
{
DecData *xData;
long long z;
xData = (DecData *) REALGetClassData(x, &DecClass);
if(!getCurr_Dec(z, *xData))
{
REALobject err = REALnewInstance("DecToCurrOverflowException");
REALRaiseException(err);
return 0;
}
return z;
}/* convertDecToCurr */
{ (REALproc) convertCurrToDec, REALnoImplementation,
"DecimalFromCurrency(x As Currency) As Decimal" },
{ (REALproc) convertDecToCurr, REALnoImplementation,
"DecimalToCurrency(x As Decimal) As Currency" }
I see no problem with the 'DecimalFromCurrency' method. In proper RB
code the x in 'x As Currency' will already be initialized.
For the 'DecimalToCurrency' method I've assumed that Currency is a 64
bit signed integer, where a decimal point is presumed placed before
the rightmost 4 decimal digits, but not actually there. So my
'convertDecToCurr' C++ function returns a long long, which is a 64 bit
signed integer. This works. RB does not object when it receives a long
long as a Currency value. If the plugin passes say 1234567891234, the
Currency value in RB becomes 123456789.1234.
So what is a possible problem? My 'convertDecToCurr' does not create
and initialize a REALobject containing a currency value, which then is
passed to RB from the plugin. An example RB source using Decimal
Plugin is:
Dim c As Currency
Dim d As Decimal
d = new Decimal("123456789.1234") // There's a method not shown here
to do this
c = DecimalToCurrency(d)
How does RB handle 'Dim c As Currency'? Is space reserved for a
pointer or a value? When 'c = DecimalToCurrency(d)' is compiled, the
compiler knows that a long long value is on the stack. What it then
does with that value is what worries me as regards the initialization
of c. Since my plugin works, it appears that c does get a proper, not
a nil, pointer. But I really would like this to be confirmed by an RB
expert before I release what might be a buggy plugin.
Bob
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>