1

I am using C++ Builder and am creating a VCL Forms application.

Here is my code:

std::string returnStringFromUnicodeString(AnsiString str)
{
std::string s(str.c_str());
return s;
}

Currently I have this in the main.cpp file and can use this function from any other functions in this .cpp file.

My question is this: How can I call this function from another GUI form? I have included the .h of the main .cpp file but still have no luck.

Do I have to make it public or some other method?

Thanks

1
  • 1
    What in your code is putting a Unicode string in an AnsiString? Commented Sep 25, 2012 at 22:49

4 Answers 4

1

You need to declare your function in a header, and you need to place the implementain in another cpp file, not ine with a main in it, so no int main or void main etc

Sign up to request clarification or add additional context in comments.

Comments

1

You probably want to put that helper function in separate header and cpp files, so that you can use it across your project.

Comments

0

You need to add:

std::string returnStringFromUnicodeString(AnsiString str);

to your main.h file.

Comments

0

A different way, is to add a prototype with extern in the form you want to use it:

extern std::string returnStringFromUnicodeString(AnsiString str);

But I think is better to use headers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.