0

hi How to allow enter only 5 char in Tedit without using tmask?
Thanks.

Edited by especta: n/a

3
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by crystalbit
Featured Replies
  • [QUOTE=especta;1094928]hi How to allow enter only 5 char in Tedit without using tmask? Thanks.[/QUOTE] [code] procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); var T: string; begin T := Edit1.Text; if (Length(T)>4) and (Key<>#8) then Key := #0; end; [/code] Key=#8 allows to be used BACKSPACE Read More

1

hi How to allow enter only 5 char in Tedit without using tmask?
Thanks.

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var
  T:      string;
begin
  T := Edit1.Text;
  if (Length(T)>4) and (Key<>#8) then
    Key := #0;
end;

Key=#8 allows to be used BACKSPACE

Comments
Thank you its help my very much
0

it would be also good to check the length in case it is more than 5 each time, because if you paste some text (using shift-ins), it won't be filtered

0

In case about pasting some text:

procedure TForm1.Edit1Change(Sender: TObject);
var
  T:      string;
begin
  T := Edit1.Text;
  if (Length(T)>4) then
  begin
    Edit1.Text := Copy(T, 1, 5);
    Edit1.SelStart := 6;
  end;  
end;

Edited by finalist: n/a

0
procedure TForm1.Edit1Change(Sender: TObject);
var
  T:      string;
begin
  T := Edit1.Text;
  if (Length(T)>5) then
  begin
    Edit1.Text := Copy(T, 1, 5);
    Edit1.SelStart := 6;
  end;  
end;
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.