Solved

C++ Builder

Posted on 1999-01-16
13
304 Views
Last Modified: 2010-04-16
I am writing a program in C++ Builder.  I'm using the string ADT and a Memo component.  I'm trying to do the following:

  string TempPalindrome;
  TempPalindrome = MemoPalindromeCandidates->Lines[1];

This is not working because Lines is of type TStrings.  I need something that is compatible with the string ADT.  For example and AnsiString would be compatible:

//This works okay.
string TempPalindromeFile;
TempPalindromeFile = openDlg->FileName.c_str();

Because FileName is an AnsiString, you can add c_str() on the end and assign the whole thing to TempPalindromeFile.

Thanks.

0
Comment
Question by:Tom Knowlton
[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
  • 8
  • 5
13 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1184379
Hello KnowIton :)

How is the game editor going?

When did you decide to use C++ Builder?

Ok, here is how you do that in C++ Builder...

String TempPalindrome;
TempPalindrome = MemoPalindromeCandidates->Lines->Strings[1];
ShowMessage(TempPalindrome);

or you could simply do this...

ShowMessage(MemoPalindromeCandidates->Lines->Strings[1]);

This is just an example... Let me know if you need more help :)

-Viktor
--Ivanov
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 1184380
Viktornet:

This works in Delphi, I'm sure...but this is C++ Builder.  I'm using the string Abstract Data Type.  It is not the same "string" type as the one in Delphi.

Your code example will definitely not work in C++ Builder.

Do you actually HAVE C++ Builder?  I'm wondering.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1184381
Yes I do have C++ Builder....

Have you tried what I gave you?

Here is what I've tested with C++ Builder and it works perfectly...

String str;

str = Memo1->Lines->Strings[0];

ShowMessage(str);

and it displays Memo1 because that's what I have in the first line in the Memo, so I think my answer was correct...

-Viktor
--Ivanov
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:viktornet
ID: 1184382
In Delphi you can do Str := Memo1.Lines[0]; but that's not the case in the Builder... In C++ Buil;der you should include the full thing as Str = Memo1->Lines->Strings[0]; The same thing can be used in Delphi... Did you actually try the code? If not you better try before rejecting... If I misunderstood something, than I apologize for that,....
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 1184383
Viktornet:

Actually...you are correct.  Just one minor change to your solution is necessary:

String TempPalindrome;
TempPalindrome = MemoPalindromeCandidates->Lines->Strings[1].c_str();

The   .c_str()   is necessary to convert the Strings[1] over to the string ADT.

Thanks for your help!

Please repost your question as an answer and I will give you your points.

As for why I am using C++ Builder...well, it's not exactly by choice.  The class I'm taking in Object Oriented Data Structures requires everything be written in C++.  Since I prefer Windows apps...C++ Builder seemed a logical choice.

The MYST clone is going so so.  I'm mostly doing design work right now.  

Talk to you later,

Tom


0
 
LVL 10

Accepted Solution

by:
viktornet earned 20 total points
ID: 1184384
What exactly is an ADT type of string?? Is it a pointer to a character?? because that's what c_str() returns?!?!....

you can do this...

String str;

str = Memo1->Lines->Strings[0];

or you copuld do this....

char *str = Memo1->Lines->Strings[0].c_str();

Well, either way... If you need more help let me know...

-Viktor
--Ivanov
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 1184385
Here you go.

Thanks!
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1184386
You mad at me for something or what? Why don't you talk a lot? And would you please tell me what an ADT type is? Thanks!
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1184387
Oh and why did you give me a B? Anything wrong with my answer? I was just trying to help...
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 1184388
I don't remember what happened with this?

I don't know why I gave you a B.

Refresh my memory.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1184389
never mind...
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 1184390
Viktor:

I posted a question on "Drag and Drop" in the C++ section.  Have you done this type of thing?
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1184391
Hello Tom!!

I just read your question... I've not tried doing such a thing, but I might try soon, and if I succeed I will let you know... It's kinda hard since I dont have much time, but if i find some spare time I will try to do that...

..-=ViKtOr=-..
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 learn how to clear a vector as well as how to detect empty vectors in C++.

733 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