0

So much information about Unicode but hard for for me to get a conclusion.

I'm working on an multi-language Delphi XE5 application and now I face this problem with this unicode characters. Honestly I don't want to understand the magic behind, I just want to see them work in my application.

Before it was simple. In general use String data type. Now I've read about WideString, UnicodeString, AnsiString and the fact that String in XE5 is compliant with UTF-16

I've tested with WideString and the lating characters like (șțăîâ) are working, but it's still not clear if WideString is the best one or not. Should I use UnicodeString or else?

So, If I should make a multi-language application that support all languages, in the end, what kind of data type should I use? Is it any possibility to maintain String type and get the same results like WideString?

Remark: I use inside my application FireDac components, but this should not matter.

REALSOFO
  • 852
  • 9
  • 37
  • 5
    You should use simply `string`. – Uwe Raabe Jan 07 '14 at 17:24
  • 2
    [TField.AsString returns an AnsiString encoded value (even if declared as string)](http://stackoverflow.com/q/9459186/458259) and TField.AsWideString returns a string=UnicodeString! It may be the root cause of your confusion. See http://blog.synopse.info/post/2013/04/22/TDataSet...-now-I-m-confused :) – Arnaud Bouchez Jan 07 '14 at 21:41

1 Answers1

2

In modern Delphi "string" is a shortcut to "UnicodeString" real data type. Use it unless have to forced to use other types.

WideString is but Delphi pseudonym for Microsoft OLE BSTR type and lacks reference counting. That disables copy-on-write optimizations and makes those string work slower than UnicodeString in general (the very data buffer is copied time and again instead of just passing new pointer to it). Unless you need exactly those features - better use usual strings. However for i18n both those types work enough.

Arioch 'The
  • 15,799
  • 35
  • 62
  • Then why with string is not working to display unicode and with widestring is working? Should I setup something to my application? – REALSOFO Jan 07 '14 at 17:32
  • Show the Code, the shorter possible example (Google sscce) that has correct chars on input, but broken chars on output. In general it just works. Probably you use some outdated library without understanding it. And do you use XE or XE5? Fix your question to only denote correct version pleade – Arioch 'The Jan 07 '14 at 17:35
  • 2
    Btw are you sure you only changed datatype and not changed used functions, like calling `. AsWideString` and `.AsString` which are different functions but they are not variables/datatypes? – Arioch 'The Jan 07 '14 at 17:43
  • I read data from a MSSQL Express DB. The unicode characters can bee seen correctly there. Then, I use FireDac to read the data from DB with a function made by me (basiclu I read as WideString because as String it doesn't show correcly: matrix[row,col]:=FDQuery1.Fields.Fields[col].AsWideString; Then I put the data in a TVirtualStringTree. Why String doesn't work? – REALSOFO Jan 07 '14 at 17:45
  • I think i get your point. If in one place I use String and in another WideString then String is no more working... I play a lot with the String and WideString to make it work and if in one place is not write then is not working. Everything must be kept as String if I understand wright! – REALSOFO Jan 07 '14 at 17:50
  • I've deleted all `WideString` data types and replace them with `String`. And it's working perfectly. Thank you! – REALSOFO Jan 07 '14 at 18:00
  • If you used `git bisect` or similar I suspect you could find breaking change yourself and much faster :-D – Arioch 'The Jan 07 '14 at 18:25
  • I once tried MSDE (which later was renamed MSSQL Express) and it was heaaaavy. On the small notebook of our accountant it installed more than 10 minutes. Today computers are faster but still I wonder why using limited and large MSSQL express when there are slim and unlimited multi-user tools like Firebird and even more embedded monopolistic engines (SQLite, NexusDB, Firebird again)... – Arioch 'The Jan 07 '14 at 18:30