Recent

Author Topic: UnicodeString in StringGrid  (Read 369 times)

Milsa

  • Full Member
  • ***
  • Posts: 213
UnicodeString in StringGrid
« on: August 01, 2020, 06:42:52 pm »
I have warnings for implicit conversion from UnicodeString (file names) to AnsiString (TStringGrid cells). Does it possible to use StringGrid with UnicodeString?
I work with Lazarus 2.0.10, FPC 3.2.0, SVN 63526
This information is actual to: 1st Aug 2020

PascalDragon

  • Hero Member
  • *****
  • Posts: 1958
  • Compiler Developer
Re: UnicodeString in StringGrid
« Reply #1 on: August 01, 2020, 07:11:41 pm »
Lazarus uses UTF-8 for AnsiString by default, so you can simply force the cast by using AnsiString(MyUnicodeStringValue), which will get rid of the warning.

Milsa

  • Full Member
  • ***
  • Posts: 213
Re: UnicodeString in StringGrid
« Reply #2 on: August 01, 2020, 09:37:47 pm »
AnsiString and UnicodeString are the same in this use?
I work with Lazarus 2.0.10, FPC 3.2.0, SVN 63526
This information is actual to: 1st Aug 2020

jamie

  • Hero Member
  • *****
  • Posts: 3275
Re: UnicodeString in StringGrid
« Reply #3 on: August 01, 2020, 11:15:28 pm »
AnsiString and UnicodeString are the same in this use?

Ansistrings are single byte sets coded using the UTF8 while UnicodeString is a double wide set using UTF16 coding..

WideString is a fixed WORD size character supposedly for windows targets but be careful there.

 @PascalDragon Knows (should know) the compile well of course if  casting of a UnicodeString converts it to UTF8 on the fly,there you go?

 Otherwise you can use the UTF16ToUTF8 functions too which I am not even sure if they are still supported.

 Also I think if you were to custom draw the cells yourself there should be some overloads in there to accept these types

« Last Edit: August 02, 2020, 03:04:06 pm by jamie »
The only true wisdom is knowing you know nothing

Bart

  • Hero Member
  • *****
  • Posts: 3856
    • Bart en Mariska's Webstek
Re: UnicodeString in StringGrid
« Reply #4 on: August 01, 2020, 11:34:03 pm »
...while UnicodeString is a double wide set using UTF8 coding..

Huh?
Typo perhaps?

Bart

PascalDragon

  • Hero Member
  • *****
  • Posts: 1958
  • Compiler Developer
Re: UnicodeString in StringGrid
« Reply #5 on: August 02, 2020, 01:46:08 pm »
AnsiString and UnicodeString are the same in this use?

No. UnicodeString is always UTF-16 (though depending on the platform it might be BigEndian or LittleEndian) and in case of Lazarus AnsiString is in UTF-8 encoding. The warning you see is because AnsiString is in fact String(CP_ACP), thus in theory the AnsiString could also be non-UTF-8, thus why the compiler warns for an implicit assignment. As you (now) know that AnsiString in Lazarus is UTF-8 you can simply force the cast by making it explicit and the compiler will no longer complain, because it trusts that you know what you're doing.

jamie

  • Hero Member
  • *****
  • Posts: 3275
Re: UnicodeString in StringGrid
« Reply #6 on: August 02, 2020, 03:01:21 pm »
You guys know well enough that was a simple mistake by looking at the rest of the message.
 
 If you want to pick a simple grammar mistakes that iron themselves out in the remaining message go ahead to do so..

 Its obvious with the message as I wrote it that I am well aware of how it works and I think the majority can agree on that.

 If you want to conduct business in this manner I can turn into a grammar junky, paraphrase king of disruption. Is that what you are really after ?

 If It will make you feel any better I'll fix the message but most of you should know better than that..

 My god, I can't believe the shenanigans some will pull just to throw a rock.

The only true wisdom is knowing you know nothing

PascalDragon

  • Hero Member
  • *****
  • Posts: 1958
  • Compiler Developer
Re: UnicodeString in StringGrid
« Reply #7 on: August 02, 2020, 03:54:15 pm »
You guys know well enough that was a simple mistake by looking at the rest of the message.

You are aware that I replied to Milsa's post and not to you?

 

TinyPortal © 2005-2018