This has the advantage that is works also when the characters are not ASCII, while using sets limits you to 256 values in the comparison. Similarly, rather than testing for the inclusion of a character in a range like: | if ch1 in [ '0'.. '9'] then ...
which compiles and works only thanks to the reduction of the chi variable to a byte char (as hinted by the related warning), you should rather code it like you'll do in most other programming languages like: | if (chl >= '0') and (chl <= '9') then ...
All of these techniques have the advantage of being backward compatible. If you need to replace your is character in set test specifically for Delphi 2009, I'd certainly recommend using the new specific CharlnSet function of the SysUtils unit:
This code is almost identical to the original test, and it is very easy to replace the older tests with the new ones when porting code to Delphi 2009. The CharlnSet function is defined for both AnsiChar and WideChar values, and uses as second parameter the set type defined below: type
TSysCharSet = set of AnsiChar;
function CharlnSet(C: AnsiChar;
const CharSet: TSysCharSet): Boolean; overload; inline; function CharlnSet(C: WideChar;
const CharSet: TSysCharSet): Boolean; overload; inline;
Another alternative approach that is quite efficient and works across versions, is to replace these tests with a case statement like: case Ch of
This also the advantage of being much faster than the CharinSet function. A final specific case is the test for inclusion in the LeadBytes set: if str[i] in LeadBytes then ...
In this case you should use the new IsLeadChar function to replace the test. In some other cases the new Unicode-related tests provided by the Character unit could help as well.
Was this article helpful?
What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.