user382591
user382591

Reputation: 1390

User language support in Delphi 7

My program is written in Delphi 7 and I want to avoid a Russian or a Chinese, Korean try to use my soft because file paths contains Unicode chars and my program can t handle them yet (as long as I do not port my program on a new Delphi version supporting UNICODE).

How do I write a function detecting the "Unicode language" in Delphi 7?

Upvotes: 0

Views: 3198

Answers (1)

Arnaud Bouchez
Arnaud Bouchez

Reputation: 43033

A Delphi 7 program (in its VCL part) can handle Russian, Chinese or Korean characters without any problem.

If the Windows system language is properly set, the charset will match the corresponding encoding, and the file names will be able to have Unicode chars as available in this charset. In fact, default string=AnsiString is converted into Unicode when the VCL calls Windows APIs (all ....A() calls will do the conversion then call the ....W() version).

You can force the default code page (the one which will select the charset to be used) by calling code like this:

if GetThreadLocale<>LCID then // force locale settings if different
  if SetThreadLocale(LCID) then
    GetFormatSettings; // resets all locale-specific variables

In this case, the TFileName (=AnsiString) in the current system charset will be converted by Windows into the corresponding Unicode characters, and you'll be able to use it in your Delphi 7 application.

What you can't do with the standard VCL AnsiString use it to directly mix charsets, as you can since Delphi 2009, thanks to the new string = UnicodeString default paradigm.

PS:

Since the CharSet only involve #128..#255 chars (i.e. all with bit 7 set), if you use only #0..#127 chars, your string will be consistent whatever the current charset/codepage setting is. If you use only English chars and numbers e.g., your path will always work, whatever the charset/codepage is. But if you use non English chars, the path will only work if the charset/codepage is correctly set, which is the case for a path used by an end-user (using a TOpenDialog at runtime for instance).

Upvotes: 5

Related Questions