Recent

Author Topic: VirtualTreeView: Internal String Type  (Read 6236 times)

AMarchant

  • New Member
  • *
  • Posts: 15
VirtualTreeView: Internal String Type
« on: October 25, 2011, 07:15:16 pm »
Hi all.

I'm an absolute Lazarus/Free Pascal beginner, so this might all be the result of some fundamental misunderstanding.

I'm trying to convert a Delphi 6 project to Lazarus. The two main visual components are a TVirtualStringTree and a TVirtualDrawTree.

In my project I created my own version of the TVirtualTreeHintWindow, and this is where I'm having problems at the moment. The thing is, it appears that many of the internal string references in VirtualTrees.pas have been changed from UnicodeString (where UnicodeString is defined as "UnicodeString = WideString") to String in the Lazarus port.

Looking at the Lazarus Wiki documentation, it seems "String" is synonymous with AnsiString with the {$H+} compiler switch (else ShortString), and looking at the Compiler Options for my project this is on by default.
So this leaves me with two questions:

1) Am I correct in understanding that the Lazarus-ported VirtualTrees are AnsiString only?
2) If not, how do I go about passing my WideString data to the functions/event handers that now expect AnsiString parameters?

Thank in advance. I don't mean to be disparaging in anyway, I can only imagine the amount of work that was involved in translating the component, and I commend the authors highly for that.
« Last Edit: October 25, 2011, 07:28:31 pm by AMarchant »

IPguy

  • Sr. Member
  • ****
  • Posts: 385
Re: VirtualTreeView: Internal String Type
« Reply #1 on: October 25, 2011, 08:35:18 pm »
Per: the FPC ref. guide (for v2.4.4, April 2011)...
    ftp://ftp.freepascal.org/fpc/docs-pdf/ref.pdf

Quote
The compiler transparantly converts WideStrings to AnsiStrings and vice versa.

However....

Quote
The compiler itself provides no support for any conversion from Unicode to ansistrings or vice versa.
The system unit has a unicodestring manager record, which can be initialized with some OS-specific
unicode handling routines. For more information, see the system unit reference.

IPguy

  • Sr. Member
  • ****
  • Posts: 385
Re: VirtualTreeView: Internal String Type
« Reply #2 on: October 25, 2011, 08:37:37 pm »
I did find this:
http://webcache.googleusercontent.com/search?q=cache:mCqfiPHPMBYJ:www.freepascal.org/docs-html/rtl/system/tunicodestringmanager.html+&cd=3&hl=en&ct=clnk&gl=us&client=firefox-a

Quote
Description

TUnicodeStringManager is currently the same as the TUnicodeStringManager manager record. It performs the same functions: converting unicode strings to ansistrings and vice-versa, performing uppercase to lowercase transformations and comparing strings.

AMarchant

  • New Member
  • *
  • Posts: 15
Re: VirtualTreeView: Internal String Type
« Reply #3 on: October 25, 2011, 09:13:04 pm »
Hi IPGuy, fancy meeting you here (I'm "Delphigher" on the SoftGems forum).

Thanks for the PDF link, it's good to have that documentation on hand. I've just been looking at:

http://edn.embarcadero.com/article/38498

...because I tend to trip up a bit on the terminology when it comes to Unicode, code points, glyphs, character sets, character encodings, multi-byte, single-byte, ASCII, ANSI, Unicode planes, codepages and all the rest of it I'm afraid.

Quote
Some conversions, however, can result in data loss, and one must watch out this when moving from one string type that includes Unicode data to another that does not. For instance, you can assign UnicodeString to an AnsiString, but if the UnicodeString contains characters that have no mapping in the active ANSI code page at runtime, those characters will be lost in the conversion.

This is really my main point of enquiry: if I want to present Unicode characters that do not have a code page mapping, I'm going to be seeing invalid character symbols onscreen.

LuizAmérico

  • Sr. Member
  • ****
  • Posts: 457
Re: VirtualTreeView: Internal String Type
« Reply #4 on: October 27, 2011, 02:11:12 am »
Currently Lazarus uses String/AnsiString to hold utf8 encoded strings and works so far. So you can have unicode in Lazarus / VTV while using string

 

TinyPortal © 2005-2018