String Parameter Passing in C++Builder

Top  Previous  Next

What is translated > Routines > Parameter types > String Parameter Passing in C++Builder

When translating Delphi code to C++, all string-based types (such as UnicodeString, AnsiString, or WideString) are passed by value, even if the Delphi declaration uses const.

This is because Delphi’s calling convention for managed string types always passes a reference-counted handle internally, not a full copy of the string.

 

Using const UnicodeString by value in C++Builder is binary compatible with Delphi and ensures correct behavior for virtual methods, overrides, and cross-language calls.

 

Although pure C++ code often prefers const UnicodeString& for efficiency, the by-value form is both safe and efficient in C++Builder because UnicodeString is a reference-counted type (passing it only increments the reference count).

 

Therefore, Delphi2Cpp always generates parameters of type const UnicodeString by value for maximum compatibility with Delphi’s ABI and to avoid ambiguity between Delphi and C++ calling conventions.



This page belongs to the Delphi2Cpp Documentation

Delphi2Cpp home  Content