Solved

Convert TString to AnsiString

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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.

739 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