Board index » cppbuilder » ansistring vs ansistring

ansistring vs ansistring

I think I've declared English as a string in my function declaration. I'm
trying to set it to the same value as a row in TStringList
CurrentQuestionList. The compiler complains that it can't convert a system
ansistring to a system ansistring. What am I doing wrong and why is it
wrong?

// load questions
void QuestionHandling::NextQuestion(String* English, String* Russian,
String* Picture)
{
if(QuestionIndex > CurrentQuestionList->Count)
    {
    English = CurrentQuestionList->Strings[QuestionIndex];
    Russian = CurrentQuestionList->Strings[QuestionIndex + 1];
    Picture = CurrentQuestionList->Strings[QuestionIndex + 2];
    QuestionIndex = QuestionIndex + 3;
    }

--
Yours,

Slartibardfast & Zephod Beeblebrox
.......................................................
Try not to spam. Your server's admin
 might get annoyed.

 

Re:ansistring vs ansistring


Quote
> complains that it can't convert a system ansistring to a system
> ansistring. What am I doing wrong and why is it

I guess the correct warning should be that you're trying to convert
AnsiString to AnsiString*.

--
Yoto Yotov

Re:ansistring vs ansistring


It looks like you're trying to use pointers so that you can return the
strings from the function to the caller, correct?  If so, it's better to use
references instead, ie:

// load questions
AnsiString English, Russian, Picture;
NextQuestion(English, Russian, Picture);

void QuestionHandling::NextQuestion(AnsiString &English, AnsiString
&Russian, AnsiString &Picture)
{
    if(QuestionIndex > CurrentQuestionList->Count)
    {
        English = CurrentQuestionList->Strings[QuestionIndex];
        Russian = CurrentQuestionList->Strings[QuestionIndex + 1];
        Picture = CurrentQuestionList->Strings[QuestionIndex + 2];
        QuestionIndex = QuestionIndex + 3;
    }

Quote
}

If you want to use pointers instead of references ( I don't see why you
should, though), then you need to dereference the pointers when assiging the
values to them:

// load questions
AnsiString English, Russian, Picture;
NextQuestion(&English, &Russian, &Picture);

void QuestionHandling::NextQuestion(AnsiString *English, AnsiString
*Russian, AnsiString *Picture)
{
    if(QuestionIndex > CurrentQuestionList->Count)
    {
        *English = CurrentQuestionList->Strings[QuestionIndex];
        *Russian = CurrentQuestionList->Strings[QuestionIndex + 1];
        *Picture = CurrentQuestionList->Strings[QuestionIndex + 2];
        QuestionIndex = QuestionIndex + 3;
    }

Quote
}

Gambit

"Slartibardfast & Zephod Beeblebrox" <Rhys_Sage I think we need an "a" in a

Quote
circle, here yahoo.com> wrote in message news:3bb20bba_1@dnews...
> I think I've declared English as a string in my function declaration. I'm
> trying to set it to the same value as a row in TStringList
> CurrentQuestionList. The compiler complains that it can't convert a system
> ansistring to a system ansistring. What am I doing wrong and why is it
> wrong?

Re:ansistring vs ansistring


Thanks Remy,
    Your suggestion made me think about what I was doing. I'd better explain
why I'm using pointers. I'm sending text to and from from the main program
to the library. I'm still half-way though designing the program. If I'd
actually designed it on paper beforehand then things might have been faster.
Having said that It's a learn-on-the-job project, designed to help me to
learn more and better programming skills and to produce a salable product in
the end as well as producing OO code that will impress possible employers.
    What this section is doing is passing two words: one in English and one
in Russian to the main program, plus a picture, eventually via the status
bar and the TEdit. It's not complete and is in gestation. There might be
many variations but the learning element is pretty important. Thanks for the
help.

// load questions
void QuestionHandling::NextQuestion(String *English, String *Russian, String
*Picture)
{
if(QuestionIndex > CurrentQuestionList->Count)
    {
    *English = CurrentQuestionList->Strings[QuestionIndex];
    *Russian = CurrentQuestionList->Strings[QuestionIndex + 1];
    *Picture = CurrentQuestionList->Strings[QuestionIndex + 2];
    QuestionIndex = QuestionIndex + 3;
    }
else // now go through wrongly answered questions
    {
    }

Quote
}

--
Yours,

Slartibardfast & Zephod Beeblebrox
.......................................................
Try not to spam. Your server's admin
 might get annoyed.

Quote
Remy Lebeau <gambi...@gte.net> wrote in message news:3bb23a41$1_1@dnews...
> It looks like you're trying to use pointers so that you can return the
> strings from the function to the caller, correct?  If so, it's better to
use
> references instead, ie:

Re:ansistring vs ansistring


I suspected as much.  Most of the time, use a reference, it's safer because
a reference forces a memory value to be valid or else it won't even compile,
but pointers can still compile and fail at runtime if you're not careful
with what you pass.

Gambit

"Slartibardfast & Zephod Beeblebrox" <Rhys_Sage I think we need an "a" in a

Quote
circle, here yahoo.com> wrote in message news:3bb26074_1@dnews...
>     What this section is doing is passing two words: one in English and
one
> in Russian to the main program, plus a picture, eventually via the status
> bar and the TEdit.

Other Threads