请教ShortString如何转换成AnsiString?

wumy_ld 2005-09-26 08:30:06
小弟用如下语句:
AnsiString strMsg = AnsiString(E.ClassName()) + ":" + E.Message;
弹出如下警告:
[C++ Warning] FCommonFunction.cpp(275): W8037 Non-const function _fastcall TObject::ClassName() called for const object

虽然可以编译过,但每次弹出这些告警,确实挺麻烦的,不知道该怎么解决,请达人指点?
...全文
143 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xrdsheng 2005-09-27
  • 打赏
  • 举报
回复
AnsiString strMsg = AnsiString(E.ClassName()) + ":" + E.Message;
应改为
AnsiString strMsg;
strMsg = strMsg+AnsiString(E.ClassName()) + ":" + E.Message;

//因为根据你写的警告信息是因为E.ClassName()为const对象或变量,它是不能被更改的。而AnsiString(E.ClassName()) + ":"时是把":"加入AnsiString(E.ClassName()),所有有警告。
wumy_ld 2005-09-27
  • 打赏
  • 举报
回复
谢谢楼上,这样还是不行哦,告警依然。
请继续指点
wumy_ld 2005-09-27
  • 打赏
  • 举报
回复
去掉const,将参数改为Exception &E就可以了。但不明白的是为什么const类型的参数就不能读取内容。
wumy_ld 2005-09-27
  • 打赏
  • 举报
回复
ft,原来是因为我传入的E是用的const:const Exception &E
wumy_ld 2005-09-27
  • 打赏
  • 举报
回复
我按楼上的解释,改成如下语句:
AnsiString strMsg;
strMsg += AnsiString(E.ClassName()) + ":" + E.Message;
结果告警还是没有消失哦。
空中猎手 2005-09-26
  • 打赏
  • 举报
回复
改成static_cast<AnsiString>(E.ClassName())
多半不出来警告乐,偶猜的
function getjhl:shortstring;stdcall;External 'reg.dll' function getrrd:shortstring;stdcall;External 'reg.dll' function getabout:shortstring;stdcall;External 'reg.dll' function regkeyexists(x:shortstring):boolean;stdcall;External 'reg.dll' function regkeydelete(x:shortstring):boolean;stdcall;External 'reg.dll' function regreadstring(x,y:shortstring):shortstring;stdcall;External 'reg.dll' function regreadinteger(x,y:shortstring):integer;stdcall;External 'reg.dll' function regwritestring(x,y,z:shortstring):boolean;stdcall;External 'reg.dll' function regwriteinteger(x,y:shortstring;z:integer):boolean;stdcall;External 'reg.dll' function inint(x:shortstring):boolean;stdcall;External 'reg.dll' function datetodate(x:shortstring;outpu:char):shortstring;stdcall;External 'reg.dll' function getbirthday(id:shortstring):shortstring;stdcall;External 'reg.dll' function getxb(id:shortstring):shortstring;stdcall;External 'reg.dll' function newtxtfile(filename,text:shortstring):boolean;stdcall;External 'reg.dll' function appendtxtfile(filename,text:shortstring):boolean;stdcall;External 'reg.dll' function readtxtfile(filename:shortstring):shortstring;stdcall;External 'reg.dll' function datatodata(str:shortstring):shortstring;stdcall;External 'reg.dll' function datetoyue(str:shortstring):shortstring;stdcall;External 'reg.dll' function datetori(str:shortstring):shortstring;stdcall;External 'reg.dll' function dateton(str:shortstring):shortstring;stdcall;External 'reg.dll'

13,826

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧