How do i construct a WideString with a diacratic in a non-unicode Delphi version?

后端 未结 3 1633
小蘑菇
小蘑菇 2021-01-19 07:13

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

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

but using it\'s decomp

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-19 08:08

    Did you try #$0301#$0061 (i.e. diacritic first)?

    OK.

    So #$.... only handles ASCII 8 bits constants in this version.

    You can just use a workaround using memory level:

    type
        TWordArray  = array[1..MaxInt div SizeOf(word)-2] of word;
        // start at [1], just as WideStrings
        // or: TWordArray  = array[0..MaxInt div SizeOf(word)-1] of word;
        PWordArray = ^TWordArray;
    
    var
      test: WideString;
    begin
      test := '12'; // or SetLength(test,2);
      PWordArray(test)[1] := $61; 
      PWordArray(test)[2] := $301;
      MessageBoxW(0, pointer(test), 'Character with diacratic', MB_ICONINFORMATION or MB_OK);
    end;
    

    This will always work since you don't play with chars/widechars and such.

    And it will also work as expected with Unicode version of Delphi.

提交回复
热议问题