Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

Share Me

  • Please share this topic with your friends. Click any of the icons below:
  • Twitter
  • facebook
  • reddit
  • email

Troubles with UnicodeString

I'm new to the LMD components and I'm confused about UnicodeStrings. I had troubles to insert an UnicodeString into a cell of a grid.

Grid->Cells[PathCol->Position][i] = L"testpath";

produced some additonal garbage characters. Then I found the following link:

Do I really have to use LMDUnicodeStrings? If yes, then please give me a code snippet, how to convert beween Delphi UnicodeString and LMDUnicodeStrings and back. Or do I have to recompile the packages with special definitions. At the moment I'm working with the lib files that were installed with setupvcl17d25.exe. I'm using C++Builder 10.2 Tokyo.


  • 5 Comments sorted by Votes Date Added
  • I should make my error example more clear: the grid component, that I used was a TLMDGrid. I expected that there were a function to insert a new row. Because there is no, I tried to create my own. The following worked well:

    void xxx::AddRow()
     int i = gv_Sources->DataRowCount;
     Grid->Cells[IncrCol->Position][i] = i;
     Grid->Cells[PathCol->Position][i] = "testpath";
    But as soon as I changed "testpath" to L"testpath", I got a lot of troubles.
  • P.S.: there is no DataSource. The gid shall work in Memory.
  • C++ prefix L represents wide-character strings, not UnicodeStrings. Please read: or

    Since Delphi/C++Builder 2009 standard string type is UnicodeString (which is supported by TLMDGrid as default conversion from/to Variant data type).


    If you need explicitely WideString support, write your own custom datasource (small example is in Grid demo included, can be certainly in-memory as well).

  • C++ prefix L represents wide-character strings (UTF-16), not UnicodeString (UTF-8). Please read:

    Since Delphi/C++Builder 2009 standard VCL string type is UnicodeString (which is supported by TLMDGrid as default conversion from/to internal Variant data type in text columns). So if your string data is in UTF-16 format, make sure to convert it beforehand.

    LMD Code can be recompiled to support WideStrings natively (see compiler switches for options, that's the way Unicode was supported before VCL Unicode support in Delphi/C++Builder 2009+), but this not something we advise or test for new compilers and which is certainly slower than the built-in Unicode string.
  • Of course, I like to use UnicodeStrings. It was your wike page, that confused me:

    and in addition my whole IDE crashed, when I was degugging the code. Therefore I couldn't continue my experiments.

    Now I have reinstalled everything and the following works:

    Grid->Cells[PathCol->Position][i] = UnicodeString(L"testpath");

    or simply

    Grid->Cells[PathCol->Position][i] = String(L"testpath");

    BTW: wchar_t arrays can be assigned as well to WideString's as to UnicodeString's.

     WideString ws = L"testpath";
     UnicodeString s = L"testpath";

    Because my PathCol is a TLMDGridTextColumn, I assumed that the correct constructor would be invoked automatically.

    Thank you! 
Sign In or Register to comment.