Working with Unicode strings in Delphi 7

16,068

Solution 1

Obviously you would be better off with Delphi 2010, since the VCL in delphi 7 is not aware of Unicode strings. You can use WideString types, and WideChar types in Delphi 7, and you can install a component set like the TNT Unicode Components to help you create a user interface that can display your results.

For a very-large-set type, consider using a bit array like TBits. A bit array of length 65536 would hold enough to contain every UTF-16 code-point. Checking if Char X is in Set Y, would be basically:

function WideCharsInSet( wcstr:WideString; wcset:TBits):Boolean;
var
 n:Integer;
 wc:WideChar;
begin
result := false;
for n := 1 to Length(wcstr) do begin
  wc := wcstr[n];
  if wcset[Ord(wc)] then
      result := true;
end;
end;

procedure Demo;
var
 wcset1:TBits;
 s:WideString;
begin
 wcset1 := TBits.Create;
 try
  // 1157 - Hangul Korean codepoint I found with Char Map
    wcset1[1157] := true;         
    // go get a string value s:
    s := WideChar(1157);
// return true if at least one element in set wcset is found in string s:
    if WideCharsInSet(s,wcset1) then begin
        Application.MessageBox('Found it','found it',MB_OK);
    end;

 finally
  wcset1.Free;
 end;

end;

Solution 2

I also recommend to switch to Delphi 2010 (why bother with 2009 anymore?)!

If in the unlikely case that you are stuck with Delphi 7 the Unicode Library from Mike Lischke may be somewhat helpful.

Solution 3

For the simple processing of strings in the manner you describe, do not be put off by suggestions that you should upgrade to the latest compiler and Unicode enabled framework. The Unicode support itself is of course provided by the underlying Windows API which is of course (directly) accessible from "non-Unicode" versions of Delphi just as much as from "Unicode versions".

I suspect that most if not all of the Unicode support that you need for the purposes outlined in your question can be obtained from the Unicode support provided in the JEDI JCL.

For any visual component support you may require the TNT control set has the appeal of being free.

Share:
16,068
Tofig Hasanov
Author by

Tofig Hasanov

My main area of interest is Computer Science; however, I have also spent at least several years studying and practicing each of the following fields: 1) Psychology - particularly psychoanalysis, group dynamics and psychology of masses 2) Philosophy - Mostly interested in practical aspects, such as dialectical logic 3) Personal Development - Some might not classify it as a separate field of study, but I have spent more than 10 years doing research and consulting in this area and I know how deep and fascinating this field is. 4) Business Management - Systems and Control theory. Spent a lot of time working on startups as well. 5) Education - Tought Machine Learning, Algorithms and Data Structures and Engineering Design classes to undergraduate students in Qafqaz University. 6) Gaming - I have played lots of games, and I have studied them as well. I believe that we can borrow a lot of tricks from successful games, especially in the area of motivation, and implement them in education and other areas. As for computer science itself, my main focus is Machine Learning, Multi-Agent Systems and Crowdsourcing. It might seem that all these subjects are completely unrelated, but they are all united in the goal to understand various aspects of human mind: how we think, how we learn, how we motivate ourselves, etc. This is what excites me most. I think that to make the world a better place, we should start with understanding and improving ourselves.

Updated on June 23, 2022

Comments

  • Tofig Hasanov
    Tofig Hasanov almost 2 years

    I need to write a program which will browse through strings of various lengths and select only those which are written using symbols from set defined by me (particularly Japanese letters). Strings will contain words written in different languages (German, French, Arabic, Russian, English etc). Obviously there is huge number of possible characters. I do not know which structure to use for that? I am using Delphi 7 right now. Can anybody suggest how to write such program?