saleem145 wrote:How do we ensure the destructor is called if new objects are created. Instead of feeding in a fixed width and depth, try feeding in rand() so every calculate creates a new object....

Saleem

I tried that, I made about 10,000 rectangles with random dimensions, and never had a problem. Of course, our example so far is not much more than a roundabout way of multiplying two numbers, but you likely have something more ambitious in mind.

I've been playing with the 64 bit problem, using my "wild idea" incorporating hex strings. We just need some handy-dandy utility functions

- Code: Select all Expand viewCollapse view
`OUString Dec2OUHex(sal_uInt64 dec)`

{

static sal_Unicode hexdigits[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};

OUString hexStr = OUString();

sal_uInt64 Quotient;

int Remainder;

if(dec > 0) {

Quotient = dec;

while(Quotient > 0)

{

Remainder = Quotient % 16;

hexStr += OUString(hexdigits[Remainder]);

Quotient /= 16;

}

} else {

hexStr = OUString(hexdigits[0]);

}

return oureverse(hexStr);

}

OUString oureverse(OUString s)

{

OUString r;

r = OUString();

long i;

for(i = s.getLength() - 1;i >= 0; i--)

{

r += OUString(s[i]);

}

return r;

}

sal_uInt64 Hex2Dec64(OUString hexStr)

{

OUString r = oureverse(hexStr);

sal_uInt64 p,val = 0;

long i,j;

int d;

for(i = 0;i < r.getLength();i++)

{

if(r[i] >= '0' && r[i] <= '9')

d = r[i] - '0';

else

d = r[i] - 'A' + 10;

p = 1;

for(j = 0;j < i;j++)

p *= 16;

val += d * p;

}

return val;

}

Then RectPtr and RectArea become

- Code: Select all Expand viewCollapse view
`OUString SAL_CALL ClassAddinsImpl::RectPtr( double width, double height)`

throw (RuntimeException)

{

CRectangle *rect;

rect = new CRectangle(width,height);

return Dec2OUHex((sal_uInt64) rect);

}

double SAL_CALL ClassAddinsImpl::RectArea( const OUString & RectPtr)

throw (RuntimeException)

{

CRectangle *rect;

sal_uInt64 ptr = Hex2Dec64(RectPtr);

rect = (CRectangle *) ptr;

return rect->area();

}

and it works (so far), but one thing to add is that since RectArea fetches the memory for whatever its argument points to, one should be careful with it.

Something like

- Code: Select all Expand viewCollapse view
`=RECTAREA(100)`

Will very likely crash, as I've discovered.

Maybe something could (should) be done with try/catch.

A cell may be formatted to show * in place of a string, suppressing numbers altogether, with

- Code: Select all Expand viewCollapse view
`;;;"*"`