Log in

View Full Version : How to only allow integers on a TEdit



laakerules
01-15-2012, 04:25 PM
How would i only allow integers to be typed into the TEdit and then have them used say for an inventory number.

Brandon
01-15-2012, 04:27 PM
StrToIntDef(TEditBox.Text, DefaultValueIfUserEntersCrap);

laakerules
01-15-2012, 04:33 PM
How would that go in and where for Tedit


Edit3 := TEdit.Create(FrmDesign);
Edit3.Parent := FrmDesign;
Edit3.Top := 350;
Edit3.Left := 75;
Edit3.Width := 100;
Edit3.Height := 27;


all i want this to do isbe able to change a global variable known as

InvNumber: Integer;

Mark
01-15-2012, 04:38 PM
ill assume you learnt this from tutorial and you have this procedure

Procedure ButtonClick(Sender: TObject);
Begin
frmDesign.ModalResult:= mrOk;
InvNumber:=StrToInt(Edit3.text);//you need to convert the value entered from a string
End;

that should work

laakerules
01-15-2012, 04:51 PM
Thanks.

Sk1nyNerd
10-26-2013, 09:43 PM
ill assume you learnt this from tutorial and you have this procedure

Procedure ButtonClick(Sender: TObject);
Begin
frmDesign.ModalResult:= mrOk;
InvNumber:=StrToInt(Edit3.text);//you need to convert the value entered from a string
End;

that should work

can you explain how that works? if a user enters 981c for his bank pin what does it do? ignore the c?

Mark
10-27-2013, 01:43 PM
would cause an error
BankPin Invalid Int value "981c"

you could make a check for this.
But really tho your not going to enter a letter to a number only field like bank pin without you noticing.