Search code examples
delphisortinginternationalizationdelphi-2009

which is the correct text comparison method for an international application...AnsiCompareText or CompareText?


I'm using Delphi 2009 to write an app that uses an Access database.

I noticed that MS Access' ORDER BY seems to be sorting international character sets like AnsiCompareText whereas throughout my app, I'm using SysUtils.CompareText.

Access' (Jet's) ORDER BY results (delphi AnsiCompareText( ) is the same)
  Nørmork
  Öster
  RAM

delphi CompareText( )
  Nørmork
  RAM
  Öster

Which is the correct call i should be using for a comparison?

Note: I am using USA English as my locale.

Sorry, I don't know so much about this. There are many web sites that discuss related topics at length but I haven't seen a discussion about which is most appropriate.

Thank you!


Solution

  • CompareText does an ASCII comparision while AnsiCompareText uses the ANSI codepage (or in Delphi 2009+ the unicode table) to compare characters. So CompareText only works if you have plain English text.