views:

196

answers:

1

Hi all,

I'm hoping someone can shed some light on this for me> What are the differences, in Delphi 2009, between the CompareStr (defined in SysUtils) and CompareString (from Windows API) functions?

Both let you specify the locale to be used, is the Windows one simply more "complete", due to the available comparison flags? Is one consequently faster than the other?

Thanks!

+4  A: 

CompareString uses locale information so that things like ae and æ are treated as matches, and sorting is appropriate for the geographical region.

CompareStr('', loInvariantLocale) is just a byte-by-byte comparison of the characters in a string. CompareStr('', loUserLocale) calls CompareString internally, so they're identical, other than the additional flags that CompareString can accept. It's also inlined, so you shouldn't see any difference in speed between it and calling CompareString directly.

Craig Peterson
Thanks Craig,I wasn't sure since the code (assembly) for CompareStr doesn't reference CompareString - or at least I didn't catch it :o)
Bourgui