I used to use Widestring in VCL.

I used to use Widestring in VCL.
Now that I work more in Firemonkey I used String.
I understand that new String=UnicodeString and ld String=AnsiString but I have class interfaces and libraries that use WideString declarations.
Is it recomended to use Widestring in Firemonkey or leave declarations as String?

Comments

  1. UnicodeString is faster and consumes less memorry than WideString.

    ReplyDelete
  2. Use WideString with COM or if you have pre Unicode Delphi. And nowhere else.

    It was never appropriate to use it with VCL unless you used TnT Unicode controls.

    ReplyDelete
  3. Widestrings are also appropriate in interfaces shared between executables and dll's (with or without com). For everything else, unicodestrings are better.

    ReplyDelete
  4. Arthur Hoornweg Unless you want to use them as return values ........ See my well known SO post.

    ReplyDelete
  5. David Heffernan I assume you're referring to the fact that Delphi implements certain function result types as OUT parameters? If both the DLL and the executable were written in Delphi, one would probably never notice.... In all other cases, yes, GPF's would fly.

    BTW a co-worker of mine needed an implementation of Gnu Gettext a couple of years ago for his Visual Basic 6 executable. He had seen that I use dxGettext for localizing my software and he wanted to do the same.

    I developed that as a Delphi 2007 DLL. It turned out that the simplest way of handling the string stuff was by using pAnsiChar as input parameters and Olevariant as the result type. VB happily accepted the widestrings once they were wrapped in variants.

    ReplyDelete
  6. Arthur Hoornweg Certainly BSTR is very useful for interop, but there are some details you have to straighten out.

    ReplyDelete
  7. I will prefer using Widestring in COM, Interfaces and as return variables.
    Thanks for comments.

    ReplyDelete
  8. R Gosp No. Not as function return values. Don't do that. Use Widestring for interop with other modules (e.g. DLLs) and for COM interfaces. That's it.

    ReplyDelete

Post a Comment