Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Общие вопросы > MaskEdit


Автор: primus 3.11.2002, 19:50
Хочу сделать "защиту от дурака" при вводе информации в форму:
Нужно чтоб вводились только цифри и я решил использовать MaskEdit, но тут же вылезла новая проблема: цифры которые вводишь можно вводить как угодно (можно делать пробелы можду цыфрами, да и просто начинать вводить не с начала строки, что при подсчете вызывает ошибку :( ), а я хочу чтоб они вводились последовательно с первого символа!!!!!

Очень жду ответа!!!!!!!!
Заранее Спасибо!!!!!!!!!!

Автор: Dayana 3.11.2002, 20:17
В свойстве EditMask установи символы 0 столько сколько нужно. 0  означает, что на месте этого символа можно вводить только цифры, и никакие другие символы.

Автор: Medved 4.11.2002, 00:05
Из справки:

Цитата

Character Meaning in mask

! If a ! character appears in the mask, optional characters are represented in the EditText as leading blanks. If a ! character is not present, optional characters are represented in the EditText as trailing blanks.
> If a > character appears in the mask, all characters that follow are in uppercase until the end of the mask or until a < character is encountered.
< If a < character appears in the mask, all characters that follow are in lowercase until the end of the mask or until a > character is encountered.

<> If these two characters appear together in a mask, no case checking is done and the data is formatted with the case the user uses to enter the data.
\ The character that follows a \ character is a literal character. Use this character to use any of the mask special characters as a literal in the data.
L The L character requires an alphabetic character only in this position. For the US, this is A-Z, a-z.
l The l character permits only an alphabetic character in this position, but doesn't require it.

A The A character requires an alphanumeric character only in this position. For the US, this is A-Z, a-z, 0-9.
a The a character permits an alphanumeric character in this position, but doesn't require it.
C The C character requires an arbitrary character in this position.
c The c character permits an arbitrary character in this position, but doesn't require it.
0 The 0 character requires a numeric character only in this position.
9 The 9 character permits a numeric character in this position, but doesn't require it.

# The # character permits a numeric character or a plus or minus sign in this position, but doesn't require it.
: The : character is used to separate hours, minutes, and seconds in times. If the character that separates hours, minutes, and seconds is different in the regional settings of the Control Panel utility on your computer system, that character is used instead.
/ The / character is used to separate months, days, and years in dates. If the character that separates months, days, and years is different in the regional settings of the Control Panel utility on your computer system, that character is used instead.

; The ; character is used to separate the three fields of the mask.
_ The _ character automatically inserts spaces into the text. When the user enters characters in the field, the cursor skips the _ character.

Автор: CLIPSA 17.11.2006, 02:36
Так как же всётаки сделать чтоб  вводились последовательно с первого символа ? 
Допустим, если ни одного символа не введено, то каретка должна быть только и только вначале, Если ввели один символ, то каретка перемещается на вторую позицию ( т.е. каретку теперь можно меремещать на первую и на вторую поизицию). Если второй символ ввели то каретка переместилась на третью позизию ( т.е. каретка теперь может находится на позиции 1,2 и 3). и т.д.

Вобщем  каретка должна находится только там где введён символ.  А не где попало (в средине , в конце) когда не введено не одного символа.

Как это сделать  smile

Автор: Guedda 17.11.2006, 08:02
Возьми простой Edit, и в OnKeyPress пропиши:
Код

if (Key not in ['0'..'9', #8]) then Key := #0;

Всё. Проблема решена.

Автор: Sunvas 17.11.2006, 13:06
Цитата(Guedda @  17.11.2006,  08:02 Найти цитируемый пост)
Возьми простой Edit, и в OnKeyPress пропиши:

    
Код

if (Key not in ['0'..'9', #8]) then Key := #0;    


Всё. Проблема решена.

Поправлю немножко:
Код

if not (Key in ['0'..'9', #8]) then Key := #0;

Автор: CLIPSA 17.11.2006, 19:39
МНе нужно чтоб в эдит было например вот так  "99-9-999". Т.е.  д Должны быть две четрочки "-" изначально. 

Автор: Rodman 17.11.2006, 19:47
Попробуй использовать
Код

if(TryStrToInt(MaskEdit.Text, IntVAR))then//или if(TryStrToFloat(MaskEdit.Text, IntVAR))then
  Showmessage('OK')
else
   Showmessage('не OK');

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)