Ad Space — Top Banner

E2034

C++ Builder Programming Language

Severity: Minor

What Does This Error Mean?

E2034 means C++ Builder cannot implicitly convert a value from one type to another. The message names both types: [BCC64 Error] E2034 Cannot convert 'TypeA' to 'TypeB'. This is a compile-time error — the types must be made compatible, either by changing the declaration or adding an explicit cast.

Affected Models

  • C++ Builder 10.x (Alexandria)
  • C++ Builder 11 (Sydney)
  • C++ Builder 12 (Athens)
  • RAD Studio 11 and 12

Common Causes

  • Assigning a numeric type to a pointer, or a pointer to a numeric type
  • Passing a const value to a function expecting a non-const parameter
  • A narrowing conversion — assigning a double to an int or a __int64 to an int
  • Mixing AnsiString and UnicodeString (or String and char*) without conversion
  • Assigning a VCL object of one type to a variable of an incompatible VCL type

How to Fix It

  1. Add an explicit cast using static_cast<TargetType>(value) when the conversion is intentional and safe.

    For numeric narrowing: int x = static_cast<int>(myDouble); For related VCL types: use dynamic_cast and check the result for nullptr.

  2. For String / AnsiString / UnicodeString conversions in VCL code, use the appropriate conversion function: AnsiString(myString) or myString.c_str() for const char*.

    C++ Builder uses UnicodeString (typedef'd as String) for all modern VCL text. Mixing String with char* or AnsiString without conversion is a common cause of E2034 in VCL applications.

  3. If the error involves const, make the receiving variable const or redesign to avoid stripping const.

    The correct fix for 'cannot convert const char* to char*' is to change the receiving parameter to const char* — not to cast away const.

Frequently Asked Questions

Is E2034 the same as MSVC C2440?

Yes — both errors mean an implicit type conversion is not allowed. The root causes, diagnosis, and fixes are identical.

How do I convert between String and std::string in C++ Builder?

To convert from String to std::string: std::string s = AnsiString(myString).c_str(); To convert from std::string to String: String s = myStdString.c_str(); For Unicode-safe conversion, use UTF8String or the System::String constructor overloads.