SRL Archive - Help

How to only allow integers on a TEdit


laakerules

2012-01-15 11:25:31

How would i only allow integers to be typed into the TEdit and then have them used say for an inventory number.

Brandon

2012-01-15 11:27:43

StrToIntDef(TEditBox.Text, DefaultValueIfUserEntersCrap);

laakerules

2012-01-15 11:33:07

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

2012-01-15 11:38:21

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

2012-01-15 11:51:56

Thanks.

Sk1nyNerd

2013-10-26 17:43:41

From: Mark
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

2013-10-27 09:43:13

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.