Ian*_*oyd 4 delphi unicode delphi-5 unicode-string widestring
我正在尝试构建一个(测试)WideString:
但使用它的分解形式:
所以我有代码片段:
var
test: WideString;
begin
test := #$0061#$0301;
MessageBoxW(0, PWideChar(test), 'Character with diacratic', MB_ICONINFORMATION or MB_OK);
end;
Run Code Online (Sandbox Code Playgroud)
除了它似乎不起作用:

这可能是一个错误MessageBox,但我会继续说,它更可能是我的代码中的错误.
我尝试过的其他一些变化:
test := WideString(#$0061#$0301);
const
SmallLetterLatinAWithAcuteDecomposed: WideString = #$0061#$0301;
test := SmallLetterLatinAWithAcuteDecomposed
test := #$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;
Run Code Online (Sandbox Code Playgroud)
Ian*_*oyd 10
最佳答案:
const
n: WideString = ''; //n=Nothing
s := n+#$0061+#$0301;
Run Code Online (Sandbox Code Playgroud)
这修复了我在下面的所有情况,否则失败.
唯一有效的变体是将其声明为常量:
AccentAcute: WideString = #$0301;
AccentAcute: WideString = WideChar($0301);
AccentAcute: WideString = WideChar(#$0301);
AccentAcute: WideString = WideString(#$0301);
Run Code Online (Sandbox Code Playgroud)
样品用法:
s := 'Pasta'+AccentAcute;
Run Code Online (Sandbox Code Playgroud)
AccentAcute: WideString = $0301;AccentAcute: WideString = #0301;
AccentAcute: WideString = WideString($0301);AccentAcute: WideString = WideString(#$0301);AccentAcute: WideChar = WideChar(#0301);
给 PastaiAccentAcute: WideChar = WideChar($0301);
给 Pasta´ 'Pasta'+WideChar($0301)Pasta´'Pasta'+#$0301Pasta´WideString('Pasta')+#$0301
我发现想到的所有基于常量的语法的摘要:
AccentAcute: WideString = #$0301; //works
AccentAcute: WideString = WideChar(#$0301); //works
AccentAcute: WideString = WideString(#$0301); //works
AccentAcute: WideString = $0301; //incompatble types
AccentAcute: WideString = WideChar($0301); //works
AccentAcute: WideString = WideString($0301); //invalid typecast
AccentAcute: WideChar = #$0301; //fails, gives Pasta´
AccentAcute: WideChar = WideChar(#$0301); //fails, gives Pasta´
AccentAcute: WideChar = WideString(#$0301); //incompatible types
AccentAcute: WideChar = $0301; //incompatible types
AccentAcute: WideChar = WideChar($0301); //fails, gives Pasta´
AccentAcute: WideChar = WideString($0301); //invalid typecast
Run Code Online (Sandbox Code Playgroud)
WideChar可以工作,只要您只附加到变量//Works
t := '0123401234012340123';
t := t+WideChar(#$D840);
t := t+WideChar(#$DC00);
//fails
t := '0123401234012340123'+WideChar(#$D840);
t := t+WideChar(#$DC00);
//fails
t := '0123401234012340123'+WideChar(#$D840)+WideChar(#$DC00);
//works
t := '0123401234012340123';
t := t+WideChar(#$D840)+WideChar(#$DC00);
//works
t := '';
t := t+WideChar(#$D840)+WideChar(#$DC00);
//fails; gives junk
t := ''+WideChar(#$D840)+WideChar(#$DC00);
//crashes compiler
t := WideString('')+WideChar(#$D840)+WideChar(#$DC00);
//doesn't compile
t := WideChar(#$D840)+WideChar(#$DC00);
Run Code Online (Sandbox Code Playgroud)
绝对打击编译器废话; 没有经过测试的病例完全测试.是的,我认识大卫,我们应该升级.