How to identify Unicode keys when a key is pressed?

My application uses Unicode characters, and I have several text fields in which I want to restrict the user to use special characters, such as : '";

begin if not (Key in ['a'..'z','A'..'Z',' ','0'..'9',#13,#8]) then Key := #0; if Key = #13 then bOk.Click; end; 

So, at this point, it allows the user to add spaces and use the backspace key to erase and, of course, enter the key for comfirm.

There are several Unicode characters that I want to enter as well. ą, č, é, į, š, ø, ū, ž and their alternatives are uppercase, but just adding them to the set as if ...

 Key in ['a'..'z','A'..'Z',' ','0'..'9',#13,#8,'ą'..'ž','Ą'..'Ž'] 

... does nothing, and I still cannot write these characters in a text box.

I would like to know how to solve this problem. Is there a way to determine if the key pressed is the Unicode character I'm looking for?

thanks

+4
source share
2 answers

If you are on D2009 or later a block named Symbol containing functions such as IsLetterOrDigit , IsLetter , etc. all the processing that you specifically need.

+7
source

When compiling applications, pay attention to tips and warnings. To ignore them, potential problems should be ignored .

You should receive a warning that "WideChar is abbreviated to char byte ...". This is the problem: Key no longer works in Unicode in your specified operation!

Warning advises using CharInSet ; you can also look at TCharacter (a special class with class functions for identifying certain categories of characters). If none of them meets your requirements, use a string constant with all valid characters and use the Pos function to determine if Key present.

Finally, you may prefer to exclude specific characters, rather than trying to think about each specific character that you want to include.

+4
source

Source: https://habr.com/ru/post/1300156/


All Articles