Connecting Tech Pros Worldwide Help | Site Map

NEED HELP IN C++

Marcin Borkowski
Guest
 
Posts: n/a
#1: Jul 19 '05
Hello

I need some small help in the Borland C++ Builder.
I need to do something with string in format like "var1|var2|var3|var4|" and
add it to some ComboBox (Items -> Add("var1"), Items -> Add("var2") etc.).

Help me, please. How can i do it in the "while" function or something?

Best regards
Martin




Wolfgang Senfter
Guest
 
Posts: n/a
#2: Jul 19 '05

re: NEED HELP IN C++


Marcin Borkowski wrote:
[color=blue]
> I need to do something with string in format like "var1|var2|var3|var4|"
> and add it to some ComboBox (Items -> Add("var1"), Items -> Add("var2")
> etc.).[/color]

use the AnsiString.

there are 2 methods. substr and pos ( or strpos ).

AnsiString tmp = "var1|var2|var3";
int charPos = tmp.pos("|");

so you have the position of the |
and with the substr you can copy the part you want

syntax: substr(index, count);

example:
Items->Add(tmp.substr(0, charPos));

delete the elemnt you added and repeat that until pos returns an error.


--
Greetings

Wolfgang
Marcin Borkowski
Guest
 
Posts: n/a
#3: Jul 19 '05

re: NEED HELP IN C++


don't work :(
i don't know c++ very well but i need to do some changes in source code that
i have got :(

PLEASE, could you write me some whilte instruction 4 this problem?
I only need to add informations from string in format "var1|var2|var3" to
the ComboBox:

It should create something like this:

ComboBox -> Items->Add("var1");
ComboBox -> Items->Add("var2");
ComboBox -> Items->Add("var3");

Adn i don't know how can i do it in while instruction :(

PLEASE, PLEASE and one more time ------> PLEASE :(

Best regards,
Martin


Użytkownik "Wolfgang Senfter" <ws@wwww.at> napisał w wiadomości
news:3f72c9c1@e-post.inode.at...[color=blue]
> Marcin Borkowski wrote:
>[color=green]
> > I need to do something with string in format like "var1|var2|var3|var4|"
> > and add it to some ComboBox (Items -> Add("var1"), Items -> Add("var2")
> > etc.).[/color]
>
> use the AnsiString.
>
> there are 2 methods. substr and pos ( or strpos ).
>
> AnsiString tmp = "var1|var2|var3";
> int charPos = tmp.pos("|");
>
> so you have the position of the |
> and with the substr you can copy the part you want
>
> syntax: substr(index, count);
>
> example:
> Items->Add(tmp.substr(0, charPos));
>
> delete the elemnt you added and repeat that until pos returns an error.
>
>
> --
> Greetings
>
> Wolfgang[/color]


Karl Heinz Buchegger
Guest
 
Posts: n/a
#4: Jul 19 '05

re: NEED HELP IN C++




Marcin Borkowski wrote:[color=blue]
>
> don't work :(
> i don't know c++ very well but i need to do some changes in source code that
> i have got :([/color]

Hire a programmer to do it.
That's what we are paid for.


--
Karl Heinz Buchegger
kbuchegg@gascad.at
Marcin Borkowski
Guest
 
Posts: n/a
#5: Jul 19 '05

re: NEED HELP IN C++


If you don't know answer 4 my question, don't post, please.
This is not the shop with help.


Użytkownik "Karl Heinz Buchegger" <kbuchegg@gascad.at> napisał w wiadomości
news:3F72D4B5.CFF1B152@gascad.at...[color=blue]
>
>
> Marcin Borkowski wrote:[color=green]
> >
> > don't work :(
> > i don't know c++ very well but i need to do some changes in source code[/color][/color]
that[color=blue][color=green]
> > i have got :([/color]
>
> Hire a programmer to do it.
> That's what we are paid for.
>
>
> --
> Karl Heinz Buchegger
> kbuchegg@gascad.at[/color]


Attila Feher
Guest
 
Posts: n/a
#6: Jul 19 '05

re: NEED HELP IN C++


Marcin Borkowski wrote:[color=blue]
> If you don't know answer 4 my question, don't post, please.
> This is not the shop with help.[/color]

Don't top post.

http://www.parashift.com/c++-faq-lit...t.html#faq-5.4

And don't demand help. Ask. So far you have got all what you have payed
for.

--
Attila aka WW


Karl Heinz Buchegger
Guest
 
Posts: n/a
#7: Jul 19 '05

re: NEED HELP IN C++




Marcin Borkowski wrote:[color=blue]
>
> If you don't know answer 4 my question, don't post, please.
> This is not the shop with help.
>[/color]

1) Don't top post
2) It would be good idea to actually *show* us what
doesn't work.
What have you tried?
What results did you get?

Don't write: "don't work :("
But instead write: I used this code

<insert your code here>

but it does not do <insert what you expect your code to do>

and somebody will show you how it's done. You actually might
learn something by doing so.
But be warned: no Borland extensions. We discuss standard C++
only in this NG. The std::string class can do perfectly what
you want to do.

--
Karl Heinz Buchegger
kbuchegg@gascad.at
Frank Schmitt
Guest
 
Posts: n/a
#8: Jul 19 '05

re: NEED HELP IN C++


Wolfgang Senfter <ws@wwww.at> writes:
[color=blue]
> Marcin Borkowski wrote:
>[color=green]
> > I need to do something with string in format like "var1|var2|var3|var4|"
> > and add it to some ComboBox (Items -> Add("var1"), Items -> Add("var2")
> > etc.).[/color]
>
> use the AnsiString.[/color]

Please don't post OT answers - AnsiString is not a part of standard C++.
Use std::string instead.

kind regards
frank

--
Frank Schmitt
4SC AG phone: +49 89 700763-0
e-mail: frankNO DOT SPAMschmitt AT 4sc DOT com
Buster Copley
Guest
 
Posts: n/a
#9: Jul 19 '05

re: NEED HELP IN C++


Marcin Borkowski wrote:[color=blue]
> If you don't know answer 4 my question, don't post, please.
> This is not the shop with help.[/color]

You should ask this question on Borland's newsgroups.
You can sign up at (hold on while I google for
"Borland newsgroups", just a second ... )
http://info.borland.com/newsgroups/ng_cbuilder.html

I don't have Builder installed so I can't look this stuff
up in the help files or test my code. You'll gave to check
the details yourself.

// Put these declarations in the 'TForm1' class
// in the 'Unit1.h' file.
TComboBox * ComboBoxes [4];
void __fastcall FillComboBoxes (AnsiString s);
struct EFillComboError { };

// Put this in the 'TForm1' constructor in 'Unit1.cpp'.
ComboBoxes [0] = ComboBox1;
ComboBoxes [1] = ComboBox2;
ComboBoxes [2] = ComboBox3;
ComboBoxes [3] = ComboBox4;

// Put this definition in 'Unit1.cpp'.
void __fastcall TForm1::FillComboBoxes (AnsiString AString)
{
std::auto_ptr <TStringList> StringList (new TStringList);

StringList->Delimiter = "|"; // ?? Check in help.
StringList->DelimitedText = AString;

if (StringList->Count != 4) throw EFillComboError ();

for (int i = 0; i != 4; ++ i)
ComboBoxes [i]->Text = StringList->Strings [i];
}

Christopher Benson-Manica
Guest
 
Posts: n/a
#10: Jul 19 '05

re: NEED HELP IN C++


Buster Copley <buster@none.com> spoke thus:
[color=blue]
> You should ask this question on Borland's newsgroups.[/color]

A noble thought, but from what I can see very few people post there. OP would
probably do better on comp.os.ms-windows.programmer.win32.

--
Christopher Benson-Manica | Jumonji giri, for honour.
ataru(at)cyberspace.org |
Buster Copley
Guest
 
Posts: n/a
#11: Jul 19 '05

re: NEED HELP IN C++


Christopher Benson-Manica wrote:
[color=blue]
> Buster Copley <buster@none.com> spoke thus:
>[color=green]
>>You should ask this question on Borland's newsgroups.[/color]
>
> A noble thought, but from what I can see very few people post there. OP would
> probably do better on comp.os.ms-windows.programmer.win32.[/color]

I used to hang around on borland.public.cppbuilder.language.cpp quite
a lot. The traffic was high and the TeamB volunteers were helpful and
would answer pretty much any and all queries. The off-topic police
didn't seem to be too much in force and the atmosphere was friendly.

Since there is a fairly large number of borland.public.cppbuilder.*
groups, some of them don't get many posts, but language.cpp, nativeapi,
vcl.components.[using|writing] and a few others are certainly worth
checking out.

For this particular question, borland.public.cppbuilder.language.cpp is
the place to go. General Win32 programmers won't know their AnsiStrings
from their elbows.

Regards,
Buster.

Christopher Benson-Manica
Guest
 
Posts: n/a
#12: Jul 19 '05

re: NEED HELP IN C++


Buster Copley <buster@none.com> spoke thus:
[color=blue]
> For this particular question, borland.public.cppbuilder.language.cpp is
> the place to go. General Win32 programmers won't know their AnsiStrings
> from their elbows.[/color]

My apologies - my news server apparently doesn't carry b.p.c.language.cpp, only
b.p.c.language (and some other zero-traffic Borland groups). Now I'm left to
wonder why my news server hates me ;)

--
Christopher Benson-Manica | Jumonji giri, for honour.
ataru(at)cyberspace.org |
Buster Copley
Guest
 
Posts: n/a
#13: Jul 19 '05

re: NEED HELP IN C++


Christopher Benson-Manica wrote:[color=blue]
> Buster Copley <buster@none.com> spoke thus:
>[color=green]
>>For this particular question, borland.public.cppbuilder.language.cpp is
>>the place to go. General Win32 programmers won't know their AnsiStrings
>>from their elbows.[/color]
>
> My apologies - my news server apparently doesn't carry b.p.c.language.cpp, only
> b.p.c.language (and some other zero-traffic Borland groups). Now I'm left to
> wonder why my news server hates me ;)[/color]

Borland reorganised the hierarchy a while back and some servers haven't
yet caught up. (Even) Google had it wrong last time I looked.

Regards,
Buster.

Buster Copley
Guest
 
Posts: n/a
#14: Jul 19 '05

re: NEED HELP IN C++


Buster Copley wrote:[color=blue]
> Marcin Borkowski wrote:
>
> I don't have Builder installed so I can't look this stuff
> up in the help files or test my code. You'll gave to check
> the details yourself.[/color]
[color=blue]
> // Put these declarations in the 'TForm1' class
> // in the 'Unit1.h' file.
> TComboBox * ComboBoxes [4];
> void __fastcall FillComboBoxes (AnsiString s);
> struct EFillComboError { };
>
> // Put this in the 'TForm1' constructor in 'Unit1.cpp'.
> ComboBoxes [0] = ComboBox1;
> ComboBoxes [1] = ComboBox2;
> ComboBoxes [2] = ComboBox3;
> ComboBoxes [3] = ComboBox4;
>
> // Put this definition in 'Unit1.cpp'.
> void __fastcall TForm1::FillComboBoxes (AnsiString AString)
> {
> std::auto_ptr <TStringList> StringList (new TStringList);
>
> StringList->Delimiter = "|"; // ?? Check in help.
> StringList->DelimitedText = AString;
>
> if (StringList->Count != 4) throw EFillComboError ();
>
> for (int i = 0; i != 4; ++ i)
> ComboBoxes [i]->Text = StringList->Strings [i];
> }[/color]

Sorry, that doesn't do what you asked at all.
This is possibly closer:

void __fastcall
TForm1::FillComboBox (TComboBox * ComboBox, AnsiString AString)
{
auto_ptr <TStringList> StringList (new TStringList);

StringList->Delimiter = "|"; // ?? Check in help.
StringList->DelimitedText = AString;

ComboBox->Items->Clear (); // ?? No idea if that's the right idiom

for (int i = 0, n = StringList.Count; i != n; ++ i)
{
ComboBox->Add (StringList->Strings [i]);
}
}

Buster
Guest
 
Posts: n/a
#15: Jul 19 '05

re: NEED HELP IN C++


Checked and tested.

void __fastcall TForm1::FillComboBox(TComboBox * ComboBox, AnsiString AString)
{
std::auto_ptr <TStringList> StringList (new TStringList);
StringList->Delimiter = '|';
StringList->DelimitedText = AString;
ComboBox->Items->Assign (StringList.get ());
ComboBox->ItemIndex = 0;
}


Buster
Guest
 
Posts: n/a
#16: Jul 19 '05

re: NEED HELP IN C++


Dammit. This is a one-liner.
In the form constructor, put

ComboBox1->Items->Delimiter='|';

Then just use

ComboBox1->Items->DelimitedText = "var1|var2|var3|var4";
ComboBox1->Text = "Choose one ...";

I bet you would have got this straight away on
"borland.public.cppbuilder.vcl.components.usin g".

Regards,
Buster.


red floyd
Guest
 
Posts: n/a
#17: Jul 19 '05

re: NEED HELP IN C++


Buster Copley wrote:[color=blue]
> Christopher Benson-Manica wrote:
>[color=green]
>> Buster Copley <buster@none.com> spoke thus:
>>[color=darkred]
>>> For this particular question, borland.public.cppbuilder.language.cpp is
>>> the place to go. General Win32 programmers won't know their AnsiStrings
>>> from their elbows.[/color]
>>
>>
>> My apologies - my news server apparently doesn't carry
>> b.p.c.language.cpp, only
>> b.p.c.language (and some other zero-traffic Borland groups). Now I'm
>> left to
>> wonder why my news server hates me ;)[/color]
>
>
> Borland reorganised the hierarchy a while back and some servers haven't
> yet caught up. (Even) Google had it wrong last time I looked.
>
> Regards,
> Buster.
>[/color]

Also, don't worry about your newsserver. Use "newsgroups.borland.com" as a newsserver
for borland groups. Similarly, for VC specific stuff, use "msnews.microsoft.com", but they're
currently getting hammered by the worms.

Duane
Guest
 
Posts: n/a
#18: Jul 19 '05

re: NEED HELP IN C++


> > Borland reorganised the hierarchy a while back and some servers haven't[color=blue][color=green]
> > yet caught up. (Even) Google had it wrong last time I looked.
> >
> > Regards,
> > Buster.
> >[/color]
>
> Also, don't worry about your newsserver. Use "newsgroups.borland.com" as[/color]
a newsserver[color=blue]
> for borland groups. Similarly, for VC specific stuff, use[/color]
"msnews.microsoft.com", but they're[color=blue]
> currently getting hammered by the worms.[/color]

Borland seems to be having problems with their server this week though...


Closed Thread