Solved

C++ Builder

Posted on 1999-01-16
13
298 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: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: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
 
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: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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 5

Author Comment

by: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: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: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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now