User Defined Functions: Array of Variant in C++?

Module \20.Reports\A6.User Defined Functions\UUserDefinedFunctions.pas, line 42:

//FUNCTIONS SHOULD ALWAYS be defined as either:
  // 1) function xxx(const Paramters: array of variant): variant
  // 2) function xxx: variant
  // Any other declaration will raise an Access Violation.

That's fine in Delphi, but I am using C++: how am I supposed to define a function that takes "an array of variant"?

Let's say I want to translate this function

function Upper(const Parameters: array of variant): variant;

in c++ I thought that this syntax would work

Variant __fastcall Upper(System::Variant const *Parameters, const int Size)

but when I execute it gives me this error: trying to access property Upper..verify that is a variant

Hi,

Variant __fastcall Upper(System::Variant const *Parameters, const int Size)

should be fine, I can't find a problem with it. Verify that it is in the published section. 
Also, note that while this is the header Delphi generates, I would use:
Variant __fastcall Upper(System::Variant const *Parameters, const int High)

Because the last parameter isn't the size or even the length of the array, but the highes component. This means that in an array with a single value, "High" will be 0, and not 1 (as it would be if it was the length).

But other than that which is purely cosmetic since the name doesn't matter, this should work. I am attaching a simple example at:
http://www.tmssoftware.com/FLEXCEL/samples/cppparams.zip

Do you see anything different in your code?

The Project you provided got me access violation. I suspect that there is something wrong with my installation. I had to remove FlexCel2007 package import: is this ringing any bell?

That's probably my fault. For the setups in C++ builder we clean a lot the files because indeed C++ builder is very sensitive t the stuff that goes in the cbproj. But here I just zipped it and sent it, hoping it would work :(  Also note that this was done in RadStudio XE2, if you have other version it might not work.


In any case: Can you reproduce the project by creating a new empty one and adding the cpp/h files, and copying the temp.xls file? When you create a new project it will have the correct imports.

Ok I recreated the project and now it works! I don't know why, though. I need to fix my main project, can you give me a few pointers? 

I compared the two cbprojs. It turns out that RadStudio is not that good at porting projects :) Also, my project has been ported from XE2, too (1 year ago). The bug was the same: I had to replace the <PackageImports> tag of the project file... honestly there was so many packages in both projects that I couldn't establish what was wrong.

I was lucky.

Indeed cbprojs are problematic files. There is too much stuff there and a wrong entry can cause C++ builder to crash. Also normally the "AllLibs" entry can be problematic, sometimes C++ builder forgets to modify entries there and thy get out of synch.

Indeed cbprojs are problematic files. There is too much stuff there and a wrong entry can cause C++ builder to crash. Also normally the "AllLibs" entry can be problematic, sometimes C++ builder forgets to modify entries there and thy get out of sync.