Solved

C++ Builder

Posted on 1999-01-16
13
305 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
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!

 
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

Technology Partners: 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

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…
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 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 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.

728 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