OriginalCodeYou cannot enter only one decimal point.
Begin
Case key
'0' .. '9', #8, #13, #45, #27, '.':; // #8 return key, #13 return key
// Enter 0-9, return, press enter, point, and negative number.
Else
Begin
MessageBox (0, 'enter a value! ', 'Input error', mb_ OK + mb_iconerror );
Key: = #0;
End;
End;
End;
Only one decimal point is allowed:
Add the following code to the keypress event: If not (key in ['0'... '9', '.', #8]) then Key: = #0; If (Key = '.') and (Pos ('.', edit1.text)> 0) then Key: = #0; POs ('.', edit1.text) obtains the position where the image appears in edit. text for the first time. As long as there is one in edit1.text, the return value must be greater than 0. |
The above code can only be applied in edit1. If you want to apply this event to multiple edits, you can make the following modifications: (other events are the same)
If not (key in ['0'... '9', '.', #8]) then Key: = #0; If (Key = '.') and (Pos ('.',Tedit (sender). Text> 0) then Key: = #0; |