convert unicodestring to string in xrad studio

会有一股神秘感。 提交于 2019-12-12 04:17:24

问题


I have a problem in "Rad Studio 10 Seattle" where I am trying to get text input from a TEdit object and I get a errormessage saying

E2034 Cannot convert 'UnicodeString' to 'string'

My code is as follows:

this->shopVar->addDog(edName->Text, StrToInt(edAge->Text), "male", "dogspecial");

This function addDog takes (string, int, string, string)
When I try to send the text from the TEdit object with edName->Text I get the errormessage mentioned earlier.

My question is as follows, can i make a convertion on edName from unicodestring to string or do I have to change the datatype of my parameterlist? If so, how do I do it?
I have been searching for this issue but have not found anything that is similar to my problem.


回答1:


You need to convert the UnicodeString data to Ansi first, then pass that instead. The easiest way is to assign the UnicodeString to an AnsiString (or derivative) first, and then use its c_str() method to get a char* pointer, which std::string will accept:

this->shopVar->addDog(AnsiString(edName->Text).c_str(), ...);

If possible, maybe consider rewriting your shopVar class to use std::wstring instead, then you can remove the Ansi conversion:

this->shopVar->addDog(edName->Text.c_str(), StrToInt(edAge->Text), L"male", L"dogspecial");


来源:https://stackoverflow.com/questions/34661481/convert-unicodestring-to-string-in-xrad-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!