Solved

C++ Builder

Posted on 1999-01-16
22
526 Views
Last Modified: 2010-05-18
I know this is the Delphi topic area...but I'm hoping some of you Delphi gurus may know how to solve this:

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 an 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
  • 11
  • 7
  • 4
22 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1362176
Memo->Lines is of type TStrings, but Memo->Lines[1] is of type string, so I don't see why it doesn't work.
In Delphi your syntax would be ok.
Perhaps you have to write:
  TempPalindrome = (MemoPalindromeCandidates->Lines[1]);
or
  TempPalindrome = (string) memoPalindromeCandidates->Lines[1];
or something like this?

Regards, Madshi.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1362177
KnowIton, please keep your points.... I've anwered your question in the C++ topic area...

Here is the solution....

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

Hope this helps...

Once again, delete this question...

-Viktor
--Ivanov
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1362178
Hi Viktor,

is there no default property in C++? In Delphi Lines[1] is exactly the same as Lines->Strings[1], because Strings is the default property of Lines.

Regards, Madshi.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1362179
Well, in Builder, there is a property lines also, but you cannot access it the way you do it in Delphi... The Builder compiler is even angrier than Delphi compiler when it comes to types, typecasting and all that ;-)
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1362180
Hi Viktor,

I don't mean that.

Look at the following extract from my help file. It's in German, so don't get confused by it...  :-)))
I think you'll get the same text in english if you tip "default" in your Delphi editor and press F1 and choose the first available help theme.

"Wenn Sie die Direktive default nach der Definition einer Array-Eigenschaft angeben, wird diese als Standardeigenschaft der betreffenden Klasse verwendet. Ein Beispiel:

type

        TStringArray = class
        public
          property Strings[Index: Integer]: string ...; default;
          ...
        end;

Auf die Array-Standardeigenschaft einer Klasse kann mit der Kurzform Objekt[Index] zugegriffen werden. Diese Anweisung ist mit Objekt.Eigenschaft[Index] identisch. Ausgehend von der vorhergehenden Deklaration kann beispielsweise StringArray.Strings[7] zu StringArray[7] verkürzt werden. Jede Klasse kann nur eine Standardeigenschaft haben. Die Standardeigenschaft kann in abgeleiteten Klassen nicht gewechselt oder verdeckt werden."

In other words, by putting this "default" keyword after a property declaration, you tell Delphi to see those two syntax variations as equal:
  lines.strings[1]
  lines[1]
Just because the "strings" property is the "default" property. It's not a less angry syntax checking, but a FEATURE!

Ok, it's really not so important, I just wondered, if there was no "default" property in C++ Builder.

Regards, Madshi.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1362181
There is not much help in C++ Builder, maybe Borland (Inprise) decided to cut it off, so Delphi gets the lead ;-)

There is a default property in C++ Builder, but I have no idea how they've declared it...

btw- I was used to write Items.Strings[<value>]; before I learned there it could be written as Items[<values>]; in Delphi... but in C++ builder it displays an error and you cannot go any furthur...

-Viktor
--Ivanov

-Viktor
--Ivanov
0
 
LVL 20

Expert Comment

by:Madshi
ID: 1362182
Hmmm. Well, I'm glad that I'm using Delphi...  :-)
The only problem with Delphi is that it is only available for Windows. I'm playing with the thought to look at BeOS, but there's no Delphi for BeOS...  :-(((

Regards, Madshi.
0
 
LVL 5

Author Comment

by:knowlton
ID: 1362183
Ladies and Gentlemen:

For some things in C++ Builder there is no direct parallel in Delphi.  This is one of those things.  :)

Here is the answer to my question:

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

Notice the    .cstr();    tacked on the end.  This converts what is being returned by Strings[index] into something the string ADT won't choke on.

Any additional questions...please ask Viktornet.  He is THE man.

Tom
0
 
LVL 5

Author Comment

by:knowlton
ID: 1362184
Viktornet:

Repost your reply in the C++ topic area as an ANSWER and I'll give you your points.

Tom

Much thanks to everyone else's efforts to solve this little tidbit.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1362185
What is an ADT kinda string? Is it a pointer to a character in C++ e.g. (char *)

if that's the case then the c_str() at the end is needed, otherwise it's not..
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1362186
So Tom, tell me what's up with the Game Editor you started some time ago in Delphi... Did you continue working on it, or you've not done anything since then?

-Viktor-
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 10

Expert Comment

by:viktornet
ID: 1362187
I answered the question in the c++ area....
0
 
LVL 5

Author Comment

by:knowlton
ID: 1362188
Viktornet:

I have not done anymore work on the Game Editor I was writing in Delphi.  It was a fun project...but school has kept me too busy.  Plus the other person working on the project with me has not had much time lately.

I'm really good at "starting" these little projects on the side...I just have a hard time finishing them.  Ha ha.

c_str() returns a C-style pointer.  It is most often used when a string value must be passed to a function that expect an older style character array.

For example:

File *fin = fopen(fileName.c_str(), "w");

I think the string ADT is basically part of the Standard Template Library.
0
 
LVL 5

Author Comment

by:knowlton
ID: 1362189
ADT stands for Abstract Data Type.

Basically...it's taking the concept of a string and incorporating all of the "wish list" functionality into it that you would normally have with other data types.  The ability to do stuff like

string temp1 = "Bill";
string temp2 = "Monica";

if(temp1 == temp2)then
  cout<<"The 2 strings are equal.";


0
 
LVL 10

Expert Comment

by:viktornet
ID: 1362190
Same here... I start projects too, but never get to finish them :))

Yeah, about the c_str() I know it returns the C type of strings which is a pointer to a character.. I just didn;t know what ADT was... and I still don't.. is it the same as the pointer to a character type of string...

is this ADT string,..

char *str;
??

Thanks!
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1362191
opps... i didn't see your last comment when I posted this.. Sorry...
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1362192
well, why don't you delete this question so you get your points back?

--Viktor
0
 
LVL 5

Author Comment

by:knowlton
ID: 1362193
Doesn't that destroy the discussion threads along with it?  Some of this discussion is beneficial...
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1362194
well, can I answer the question then so it gets into the PAQ area?
0
 
LVL 5

Author Comment

by:knowlton
ID: 1362195
Yeah go ahead.
0
 
LVL 10

Accepted Solution

by:
viktornet earned 20 total points
ID: 1362196
K
0
 
LVL 5

Author Comment

by:knowlton
ID: 1362197
Thanks.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

12 Experts available now in Live!

Get 1:1 Help Now