在Xrad Studio中将unicodestring转换为字符串 [英] convert unicodestring to string in xrad studio
问题描述
我在 Rad Studio 10 Seattle中遇到问题,我试图从 TEdit
对象获取文本输入,并且收到一条错误消息,说
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无法将'UnicodeString'转换为'string'
E2034 Cannot convert 'UnicodeString' to 'string'
我的代码如下:
this->shopVar->addDog(edName->Text, StrToInt(edAge->Text), "male", "dogspecial");
此功能 addDog
需要(字符串,整数,字符串,字符串)
当我尝试从 TEdit
对象发送文本时, edName->文本
我收到了前面提到的错误消息。
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.
我的问题如下,我可以在 edName
上从unicodestring转换为string还是我必须更改我的参数列表的数据类型?如果是这样,该怎么办?
我一直在搜索此问题,但未发现与我的问题类似的任何东西。
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.
推荐答案
您需要先将 UnicodeString
数据转换为Ansi,然后将其传递。最简单的方法是先将 UnicodeString
分配给 AnsiString
(或派生),然后使用其 c_str()
方法获取 char *
指针,该指针 std :: string
将接受:
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(), ...);
如果可能,也许考虑重写您的 shopVar
类使用 std :: wstring
代替,则可以删除Ansi转换:
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");
这篇关于在Xrad Studio中将unicodestring转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!