array of const for C++Builder |
Top Previous Next |
What is translated > Types > Arrays > Array parameters > array of const > array of const for C++Builder
For C++Builder the value of an array of const is represented by two values: a pointer to a TVarRec and the index of the last element of the array, which begins at the position which the pointer points to.
procedure foo(Args : array of const);
->
void __fastcall foo ( TVarRec* Args, const int Args_Size );
When such a functions is called with a set as argument, the macro ARRAYOFCONST is used into the C++ output.
foo(['hello', 'world']); -> foo ( ARRAYOFCONST(( "hello", "world" )) );
This macro is defined for the C++Builder as:
#define ARRAYOFCONST(values) OpenArray<TVarRec>values, OpenArrayCount<TVarRec>values.GetHigh()
The class OpenArray<TVarRec> is constructed in a manner, that it's address is equal to the pointer TVarRec* used in the signature of foo above.
There is a small difference between Delphi and C++Builder concerning character pointers like 'abc'. In Delphi 'abc' is stored as VUnicodeString, at C++Builder the TVarRec constructor for character pointers is used and therefore the value is stored as VPWideChar.
procedure foo(const constArray : Array of const)
case constArray[i].VType of vtPChar: pac := constArray[i].VPChar; vtPWideChar: pwc := constArray[i].VPWideChar; vtAnsiString: sa := AnsiString(constArray[i].VAnsiString); vtWideString: sw := WideString(constArray[i].VWideString); vtUnicodeString: su := UnicodeString(constArray[i].VUnicodeString); end; // Delphi: foo8['abc') => su = 'abc'; // C++Builder: foo8['abc') => pwc = 'abc';
|
This page belongs to the Delphi2Cpp Documentation |
Delphi2Cpp home Content |