Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/ActiveX/Framework/Variants    [ Add a report in this area ]  
Report #:  48646   Status: Closed
Error casting a Variant to an AnsiString
Project:  C++Builder Build #:  11.0.2709.7128
Version:    11.0 Submitted By:   Mats Wallin
Report Type:  Basic functionality failure Date Reported:  7/6/2007 7:23:22 AM
Severity:    Serious / Highly visible problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All platforms Internal Tracking #:   249428
Resolution: As Designed (Resolution Comments) Resolved in Build: : 11.0.2709.7128
Duplicate of:  None
Voting and Rating
Overall Rating: (1 Total Rating)
5.00 out of 5
Total Votes: None
Description
The compiler fails with an error message when I attempt to cast a Variant to an AnsiString. Previous versions of C++Builder (6 and 2006) has been able to do this.
Steps to Reproduce:
The following code fails to compile:

  AnsiString str;
  Variant var;

  var = "Hello World!";
  str = (AnsiString) var;
Workarounds
None
Attachment
None
Comments

Registered User at 7/16/2007 1:27:19 AM -
Also

[BCC32 Error] navvar.cpp(886): E2015 Ambiguity between '_fastcall System::WideString::WideString(const System::WideString &) at c:\program files\codegear\rad studio\5.0\include\vcl\wstring.h:30' and '_fastcall System::WideString::WideString(const System::AnsiString &) at c:\program files\codegear\rad studio\5.0\include\vcl\wstring.h:31'

When compiling the following


Variant var;


....


WideString wsVar;

wsVar = (WideString)var;

As mentioned by the reporter this code would previously compile with BDS and earlier versions.
NEEDS WORKAROUND!

Clayton Arends at 8/26/2007 8:51:46 AM -
The workaround is to explicitly use the conversion operator.

  wsvar = var.operator WideString();

Clayton Arends at 8/26/2007 8:54:40 AM -
I have encountered this problem in a converted project.  However; if I create a new application the implicit conversions work just fine.

  Variant v;
  WideString ws = v;
  AnsiString str = v;

Server Response from: ETNACODE01