Solved

Convert TString to AnsiString

Posted on 1998-05-20
5
3,806 Views
Last Modified: 2012-06-27
     Hi.

I have a question about Borland C++.
I have Delphi too, and there I can do this

Edit1.Text := ListBox.Items[3];

but when I do the same thing in C++

Edit1.Text = ListBox.Items[3];

I get the error "Can't convert from TString to AnsiString".
I have tried to cast like this

Edit1.Text = (AnsiString*) ListBox.Items[3];

but it doesn't help.

How should I do?
/Pelle
0
Comment
Question by:PerBoman
5 Comments
 
LVL 3

Expert Comment

by:Norbert
ID: 1164374
Hi,
I have no Borland C++ but I guess that VC++ class CString
is very similar to Borlands TString
CString has a cast operator called LPCTSTR that returns a const char* for non unicode and const WCHAR* for unicode so have a look to the operators TString offers to you I bet there is one that you can use

0
 
LVL 11

Expert Comment

by:alexo
ID: 1164375
Try either:
    Edit1.Text = (char*) ListBox.Items[3];
or
    Edit1.Text = ListBox.Items[3].Relinquish();

Tell me if it worked.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1164376
It is hard to say without knowing the type of either ListBox or Edit1.  But you might want to try

   Edit1.Text = (AnsiString) ListBox.Items[3];

The only operator = supported by AnsiString is from another AnsiString, so the right side must be an AnsiString or you canit use operator =.
0
 
LVL 1

Accepted Solution

by:
bsimser earned 200 total points
ID: 1164377
The ListBox->Items[3] variable is a TStrings type, not a TString. It's a collection of TString objects. In the TStrings class there's a variable called Strings which is an array of TString types. These are the AnsiString types. What you want to do is this:

Edit1->Text = ListBox->Items->Strings[3];

Enjoy.

-Bil
0
 

Author Comment

by:PerBoman
ID: 1164378
Ooh, that's easy!
Thanks.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
C++ standard library based binary archive format 6 104
Least Squares Curve Fitting 4 99
Header of docx file 17 117
What is sub-make ? 2 71
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question