0

Is there a way to limit the characters to numbers and lenght to 10 with no space and another edit for just ? its for a phone number, and name that needs to have no spaces, dont have an idea how to do it. Found a code that try some ways to implement but dont work here is what I found for dont allow letters.

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if (Key in ['a'..'z']) or (Key in ['A'..'Z'])  then
    Key := #0;
end;

Here for dont allow numbers:

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key in ['0'..'9'] then
    Key := #0;
end;

and this for no space:

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if key = Char(VK_SPACE) then
    Key := #0;
end;

can implement something similar in inno?

1 Answers1

0

You can edit MaxLength property of Edit1 to limit character

Edit1.MaxLength:=10;
Vuio
  • 140
  • 1
  • 7
  • 2
    `TEdit` has no **Caption** property :) use **Text** property ! `copy(...)` is not needed : use `key := #0` instead – moskito-x Jun 17 '17 at 11:55
  • 1
    I think **Text** property and **Caption** property are equivalent. I did not know `key:=#0` in **KeyPress** event, thank you – Vuio Jun 17 '17 at 12:29
  • 2
    **Also take care :** At the monent you are inside `Edit1KeyPress()` event. That means `Edit1.Text` is not altered at the moment you do copy(...) !!! with a remove of the last char you remove a valid char. Not setting `Key := 0;` you now added a number behind last killed char : START : **abcd** removed `d` and added e.g. 5 Result in Edit1.Text = **abc5** . Please improve your answer or delete them. – moskito-x Jun 17 '17 at 16:28
  • 2
    This answer is for Delphi, while the question is about Inno setup. So this is all completely irrelevant. – Martin Prikryl Jun 18 '17 at 16:38
  • 1
    @MartinPrikryl : I agree ! Only `Edit1.MaxLength:=10;` is correct. – moskito-x Jun 18 '17 at 18:10