?
Solved

Convert TString to AnsiString

Posted on 1998-05-20
5
Medium Priority
?
4,086 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 600 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

650 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