In Delphi 6, I used the following function to discover Unicode specifications.
const //standard byte order marks (BOMs) UTF8BOM: array [0..2] of AnsiChar =
This will detect all standard specifications. You can use it to lock such files if you need this behavior.
You declare that Delphi 6 TStringList can load 16-bit encoded files if they do not have a specification. Although this may be the case, you will find that for characters in the ASCII range, each other character is #0 . I think this is not what you want.
If you want this text to be Unicode for files without specifications, you can use IsTextUnicode . However, it can give false positives. This is a situation where I suspect that it is better to ask for forgiveness than permission.
Now, if I were you, I would not try to block Unicode files. I would read them. Use the TNT Unicode library. The class you want is called TWideStringList .
source share