如何在非Unicode中Delphi版本中构造一个WideString, [英] How do i construct a WideString with a diacratic in a non-unicode Delphi version?

查看:142
本文介绍了如何在非Unicode中Delphi版本中构造一个WideString,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


á(,但我要继续说,这个错误更可能是我的代码。



我尝试过的其他一些变体:

  test:= WideString(# $ 0061#$ 0301); 


const
SmallLetterLatinAWithAcuteDecomposed:WideString =#$ 0061#$ 0301;
test:= SmallLetterLatinAWithAcuteDecomposed


test:=#$ 0061 +#$ 0301; (不编译;不兼容的类型)


test:= WideString(#$ 0061)+ WideString(#$ 0301); (不编译;崩溃编译器)


test:='a'+ WideString(#$ 0301); (不编译;崩溃编译器)


// Arnauld的想法:
test:=#$ 0301#$ 0061;



Bonus chatter




解决方案

最佳答案

  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;

    img src =https://i.stack.imgur.com/Bji3n.pngalt =enter image description here>

  • AccentAcute:WideString = WideString($ 0301);

    无效的类型转换

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

    无效的类型转换

  • AccentAcute :WideChar = WideChar(#0301);
    给出 Pastai

  • AccentAcute:WideChar = WideChar($ 0301);
    给出 Pasta'



其他语法失败




  • 'Pasta'+ WideChar($ 0301)

    给出 Pasta'

  • 'Pasta'+#$ 0301

    给出 Pasta'

  • WideString('Pasta')+#$ 0301




< hr>

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

  AccentAcute:WideString =#$ 0301; // works 
AccentAcute:WideString = WideChar(#$ 0301); // works
AccentAcute:WideString = WideString(#$ 0301); // works
AccentAcute:WideString = $ 0301; // unfatble类型
AccentAcute:WideString = WideChar($ 0301); // works
AccentAcute:WideString = WideString($ 0301); // invalid typecast

AccentAcute:WideChar =#$ 0301; //失败,给Pasta'
AccentAcute:WideChar = WideChar(#$ 0301); //失败,给Pasta'
AccentAcute:WideChar = WideString(#$ 0301); //不兼容的类型
AccentAcute:WideChar = $ 0301; //不兼容的类型
AccentAcute:WideChar = WideChar($ 0301); //失败,给Pasta'
AccentAcute:WideChar = WideString($ 0301); // invalid typecast



重新排列 WideChar 可以工作,只要你只附加一个变量



  // Works 
t:='0123401234012340123';
t:= t + WideChar(#$ D840);
t:= t + WideChar(#$ DC00);

// failed
t:='0123401234012340123'+ WideChar(#$ D840);
t:= t + WideChar(#$ DC00);

// failed
t:='0123401234012340123'+ WideChar(#$ D840)+ WideChar(#$ DC00);

// works
t:='0123401234012340123';
t:= t + WideChar(#$ D840)+ WideChar(#$ DC00);

// works
t:='';
t:= t + WideChar(#$ D840)+ WideChar(#$ DC00);

// failed;给出垃圾
t:=''+ WideChar(#$ D840)+ WideChar(#$ DC00);

//崩溃编译器
t:= WideString('')+ WideChar(#$ D840)+ WideChar(#$ DC00);

//不编译
t:= WideChar(#$ D840)+ WideChar(#$ DC00);

绝对打击编译器废话;未经测试的病例已完全测试。是的,我知道大卫,我们应该升级。


i am trying to construct a (test) WideString of:

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

but using it's decomposed form:

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

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 := 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;

Bonus chatter

解决方案

Best answer:

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

s := 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 work

  • AccentAcute: WideString = $0301;
    incompatible types
  • AccentAcute: WideString = #0301;
    gives
  • AccentAcute: WideString = WideString($0301);
    invalid typecast
  • AccentAcute: WideString = WideString(#$0301);
    invalid typecast
  • AccentAcute: WideChar = WideChar(#0301); gives Pastai
  • AccentAcute: WideChar = WideChar($0301); gives Pasta´

Other syntaxes that fail

  • 'Pasta'+WideChar($0301)
    gives Pasta´
  • 'Pasta'+#$0301
    gives Pasta´
  • WideString('Pasta')+#$0301
    gives

Summary of all constant based syntaxes i found think up:

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

Rearranging WideChar can work, as long as you only append to a variable

//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);

Definitely hitting against compiler nonsense; cases that weren't tested tested fully. Yes, i know David, we should upgrade.

这篇关于如何在非Unicode中Delphi版本中构造一个WideString,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆