• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 539
  • Last Modified:

C++ Builder

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
Tom Knowlton
Asked:
Tom Knowlton
  • 11
  • 7
  • 4
1 Solution
 
MadshiCommented:
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
 
viktornetCommented:
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
 
MadshiCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
viktornetCommented:
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
 
MadshiCommented:
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
 
viktornetCommented:
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
 
MadshiCommented:
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
 
Tom KnowltonWeb developerAuthor Commented:
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
 
Tom KnowltonWeb developerAuthor Commented:
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
 
viktornetCommented:
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
 
viktornetCommented:
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
 
viktornetCommented:
I answered the question in the c++ area....
0
 
Tom KnowltonWeb developerAuthor Commented:
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
 
Tom KnowltonWeb developerAuthor Commented:
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
 
viktornetCommented:
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
 
viktornetCommented:
opps... i didn't see your last comment when I posted this.. Sorry...
0
 
viktornetCommented:
well, why don't you delete this question so you get your points back?

--Viktor
0
 
Tom KnowltonWeb developerAuthor Commented:
Doesn't that destroy the discussion threads along with it?  Some of this discussion is beneficial...
0
 
viktornetCommented:
well, can I answer the question then so it gets into the PAQ area?
0
 
Tom KnowltonWeb developerAuthor Commented:
Yeah go ahead.
0
 
viktornetCommented:
K
0
 
Tom KnowltonWeb developerAuthor Commented:
Thanks.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 11
  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now