本文介绍了如何在非Unicode中Delphi版本中构造一个WideString,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在尝试构建一个(测试) WideString :but using it's decomposed form:So i have the code fragment:var test: WideString;begin test := #$0061#$0301; MessageBoxW(0, PWideChar(test), 'Character with diacratic', MB_ICONINFORMATION or MB_OK);end;Except it doesn't appear to work:This could be a bug in MessageBox, but i'm going to go ahead and say that it's more likely the bug is in my code.Some other variations i have tried:test := WideString(#$0061#$0301);const SmallLetterLatinAWithAcuteDecomposed: WideString = #$0061#$0301;test := SmallLetterLatinAWithAcuteDecomposedtest := #$0061+#$0301; (Doesn't compile; incompatible types)test := WideString(#$0061)+WideString(#$0301); (Doesn't compile; crashes compiler)test := 'a'+WideString(#$0301); (Doesn't compile; crashes compiler)//Arnauld's thought:test := #$0301#$0061;Bonus chatterHandling a Unicode String in Delphi Versions <= 2007 解决方案 Best answer:const n: WideString = ''; //n=Nothings := n+#$0061+#$0301;This fixes all cases i have below that otherwise fail.The only variant that works is to declare it as a constant:AccentAcute: WideString = #$0301;AccentAcute: WideString = WideChar($0301);AccentAcute: WideString = WideChar(#$0301);AccentAcute: WideString = WideString(#$0301);Sample Usage:s := 'Pasta'+AccentAcute;Constant based syntaxes that do not workAccentAcute: WideString = $0301; incompatible typesAccentAcute: WideString = #0301;givesAccentAcute: WideString = WideString($0301);invalid typecastAccentAcute: WideString = WideString(#$0301);invalid typecastAccentAcute: WideChar = WideChar(#0301); gives PastaiAccentAcute: WideChar = WideChar($0301); gives Pasta´Other syntaxes that fail'Pasta'+WideChar($0301)gives Pasta´'Pasta'+#$0301gives Pasta´WideString('Pasta')+#$0301givesSummary of all constant based syntaxes i found think up:AccentAcute: WideString = #$0301; //worksAccentAcute: WideString = WideChar(#$0301); //worksAccentAcute: WideString = WideString(#$0301); //worksAccentAcute: WideString = $0301; //incompatble typesAccentAcute: WideString = WideChar($0301); //worksAccentAcute: WideString = WideString($0301); //invalid typecastAccentAcute: WideChar = #$0301; //fails, gives Pasta´AccentAcute: WideChar = WideChar(#$0301); //fails, gives Pasta´AccentAcute: WideChar = WideString(#$0301); //incompatible typesAccentAcute: WideChar = $0301; //incompatible typesAccentAcute: WideChar = WideChar($0301); //fails, gives Pasta´AccentAcute: WideChar = WideString($0301); //invalid typecastRearranging WideChar can work, as long as you only append to a variable//Workst := '0123401234012340123';t := t+WideChar(#$D840);t := t+WideChar(#$DC00);//failst := '0123401234012340123'+WideChar(#$D840);t := t+WideChar(#$DC00);//failst := '0123401234012340123'+WideChar(#$D840)+WideChar(#$DC00);//workst := '0123401234012340123';t := t+WideChar(#$D840)+WideChar(#$DC00);//workst := '';t := t+WideChar(#$D840)+WideChar(#$DC00);//fails; gives junkt := ''+WideChar(#$D840)+WideChar(#$DC00);//crashes compilert := WideString('')+WideChar(#$D840)+WideChar(#$DC00);//doesn't compilet := WideChar(#$D840)+WideChar(#$DC00);Definitely hitting against compiler nonsense; cases that weren't tested tested fully. Yes, i know David, we should upgrade. 这篇关于如何在非Unicode中Delphi版本中构造一个WideString,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-17 20:55
查看更多