In edit, only numbers, decimal points (only one decimal point is allowed), and minus signs + multiple edits share one event.

Source: Internet
Author: User

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.