gpt4 book ai didi

delphi - 如何在非 unicode Delphi 版本中构造带有变音符号的 WideString?

转载 作者:行者123 更新时间:2023-12-03 15:18:46 28 4
gpt4 key购买 nike

我正在尝试构建一个(测试)WideString:

á (U+00E1 Small Letter Latin A with acute)

但是使用它的分解形式:

LATIN SMALL LETTER A (U+0061) COMBINING ACUTE ACCENT (U+0301)

所以我有代码片段:

var
test: WideString;
begin
test := #$0061#$0301;
MessageBoxW(0, PWideChar(test), 'Character with diacratic', MB_ICONINFORMATION or MB_OK);
end;

但它似乎不起作用:

enter image description here

可能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;

奖金闲聊

最佳答案

最佳答案:

const
n: WideString = ''; //n=Nothing

s := n+#$0061+#$0301;

这修复了我下面遇到的所有情况,否则会失败。

<小时/>

唯一有效的变体是将其声明为常量:

AccentAcute: WideString = #$0301;
AccentAcute: WideString = WideChar($0301);
AccentAcute: WideString = WideChar(#$0301);
AccentAcute: WideString = WideString(#$0301);

用法示例:

s := 'Pasta'+AccentAcute;

基于常量的语法不起作用

  • AccentAcute:WideString = $0301;
    不兼容的类型
  • AccentAcute:WideString = #0301;
    给出 enter image description here
  • AccentAcute:WideString = WideString($0301);
    类型转换无效
  • AccentAcute:WideString = WideString(#$0301);
    类型转换无效
  • AccentAcute: WideChar = WideChar(#0301);
    给出Pastai
  • AccentAcute: WideChar = WideChar($0301);
    提供意大利面

其他失败的语法

  • '意大利面'+WideChar($0301)
    提供意大利面
  • '意大利面'+#$0301
    提供意大利面
  • WideString('意大利面')+#$0301
    给出 enter image description here
<小时/>

我发现的所有基于常量的语法的总结:

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

只要您仅附加到变量,重新排列 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);

绝对是针对编译器的废话;未经过充分测试的案例。是的,我知道大卫,我们应该升级。

关于delphi - 如何在非 unicode Delphi 版本中构造带有变音符号的 WideString?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7029274/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com