Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Edit Input to Edit Box

Status
Not open for further replies.

gforrest

Programmer
Apr 26, 2000
39
0
0
CA
Hi,

I want to restrict the input of an Edit Box to numeric values only. No alpha characters.

Anyone know how I do this?

Thanks.
 
You can use a mask edit component, but personally I found it has to many restrictions.

What I generally do is OnChange event convert the text to a
number, and generating some messages;



procedure Form.Edit1Change(Sender: TObject);
begin
val(edit11.text,dip,code); //convert to number
if code = 0 then
begin
Do_Some_Stuff;
end
else
begin
Vol1.Caption := '-----';
warning.caption := 'invalid input';
illegal_operations;
end;



There are other ways, but if your input must be in a specified range, you have to test it before further processing.


Regards
S. van Els
SAvanEls@cq-link.sr
 
Or you can try this:

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not ((Key >= #48) and (Key <= #57)) then
begin
Key := #0;
end;
end;

HTH,
Alphonsus.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top