Solved

Convert TString to AnsiString

Posted on 1998-05-20
5
3,731 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now