Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C++ Builder

Posted on 1999-01-16
13
Medium Priority
?
323 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
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 60 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

876 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