Board index » cppbuilder » Loading a Combo Box with an Array of Dereference Pointers

Loading a Combo Box with an Array of Dereference Pointers

I am trying to load a Combo Box with an array of dereference pointers with "ComboBox1->Items->Add(*pword[i]);".  However, I get a Complier error message that it cannot convert std basic_string to System AnsiString.  The standard Complier message for this error is "Cannot convert 'type1' to 'type2' ".  I am able to display this array in a console application using " cout << endl << *pwords[i]; ".  

I am a beginning C++ programer and would appreciate any suggestions that would help me make the proper conversion.

Fred Hill
fhill...@msn.com

 

Re:Loading a Combo Box with an Array of Dereference Pointers


Beginning programmers are very welcome here, but you need to read the
guidlines (at www.borland.com) and select the correct group for your
question.  Indeed, I'm not sure what the right group for this one
is...If you had known the answer, you might have chosen .language
(because it's about the STL), or vcl.components.using, because it's
about AnsiStrings and TComboBox.  I hope I have been able to prevent
my newsreader from replying (in kind) in HTML, since that is not
allowed in the guidelines.

I'm assuming that your objective is to load the ComboBox with the
strings from an array of std:string.

You will see that most of the VCL components use a string data object
called AnsiString.  Alas, it has nothing to do with std::string, and
doesn't even have a constructor for a std::string, which is why your
assignment statement cannot be compiled.  I'm ashamed to say I don't
use std::string much, but I think what you need to say is something
like:

...->Add(*pword[i].c_str());

If I have it wrong, you need to find the std::string method that
returns an old c-style char * string.  That *can* be converted to
AnsiString.  When, ocasionally, the compiler fails to recognize this
conversion, you can say,
String(s.c_str()) or AnsiString(s.c_str()).  If this seems cumbersome
to you, just wait until you get to enjoy how the whole VCL works
together with AnsiStrings....It's worth it.
-------
Timothy H. Buchman
========================================
City Center Theater, New York NY
mailto:tbuchmanREMOVE@NO_SPAMcitycenter.org
Please treat this signature information as confidential.
========================================
Search .borland message archive on http://www.mers.com/searchsite.html

Quote
FHill909 <FHILL...@email.msn.com> wrote in message

news:39d53e34_1@dnews...
I am trying to load a Combo Box with an array of dereference pointers
with "ComboBox1->Items->Add(*pword[i]);".  However, I get a Complier
error message that it cannot convert std basic_string to System
AnsiString.  The standard Complier message for this error is "Cannot
convert 'type1' to 'type2' ".  I am able to display this array in a
console application using " cout << endl << *pwords[i]; ".
I am a beginning C++ programer and would appreciate any suggestions
that would help me make the proper conversion.

Fred Hill
fhill...@msn.com

Other Threads