Recent

Author Topic: Is there a component like TEdit that only takes numbers in?  (Read 16428 times)

mandeepmavi

  • New Member
  • *
  • Posts: 10
Hello friends. Looking for a component like TEdit that only takes numbers in? I tried SpinEdit but this have UP DOWN arrow which i do not need. or can i disable or remove.

I am unable to install Fshcomp on v0.9.30. tried lots of things but no luck.
Or any other method to enter Number from keyboard and buttons on panel.
Thakns

Bart

  • Hero Member
  • *****
  • Posts: 5663
    • Bart en Mariska's Webstek
Re: Is there a component like TEdit that only takes numbers in?
« Reply #1 on: June 08, 2012, 11:08:11 pm »
Try T(Float)SpinEdit.
I think it's on the [Misc]-Tab

Bart

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Is there a component like TEdit that only takes numbers in?
« Reply #2 on: June 08, 2012, 11:16:24 pm »
You can use TEdit.  I was in a hurry so this code is not pretty but it will show you how.

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: char);
begin
  case Key of
    '0'..'9': begin end;

  else Key:= #0;

  end;
end;
Lazarus Trunk / fpc 2.6.2 / Win32

Bart

  • Hero Member
  • *****
  • Posts: 5663
    • Bart en Mariska's Webstek
Re: Is there a component like TEdit that only takes numbers in?
« Reply #3 on: June 08, 2012, 11:38:57 pm »
Why would you insist on using a TEdit when a custom made component for editing integers and floats is already available and has the advantage of a Value property?

Bart

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Is there a component like TEdit that only takes numbers in?
« Reply #4 on: June 08, 2012, 11:40:48 pm »
No one is insisting on anything.
Lazarus Trunk / fpc 2.6.2 / Win32

mandeepmavi

  • New Member
  • *
  • Posts: 10
Re: Is there a component like TEdit that only takes numbers in?
« Reply #5 on: June 08, 2012, 11:48:57 pm »
Thanks friends,
1, Avishai good idea but with this Backspace is also diabled.

2. Bart i tried TSpinEdit but this one have a increment arrows which i do not need.



Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Is there a component like TEdit that only takes numbers in?
« Reply #6 on: June 09, 2012, 12:04:14 am »
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: char);
begin
  case Key of
    '0'..'9': ;
    #8: ;  // the backspace key
  else Key:= #0;

  end;
end;

You can add whatever Keys you want to allow to the Case statement. '+','-','.' or any other key.
Lazarus Trunk / fpc 2.6.2 / Win32

mandeepmavi

  • New Member
  • *
  • Posts: 10
Re: Is there a component like TEdit that only takes numbers in?
« Reply #7 on: June 09, 2012, 12:07:32 am »
Good Job, i will try. and will do some exercise if it work. Thanks

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: Is there a component like TEdit that only takes numbers in?
« Reply #8 on: June 09, 2012, 09:17:05 am »
Maybe TMaskEdit could solve this issue too. Not sure, however since I rarely use it.

Bart

  • Hero Member
  • *****
  • Posts: 5663
    • Bart en Mariska's Webstek
Re: Is there a component like TEdit that only takes numbers in?
« Reply #9 on: June 09, 2012, 05:20:59 pm »
Maybe TMaskEdit could solve this issue too. Not sure, however since I rarely use it.
You would have to specify a mask like '9999999;1;_' , but as you can see this isn't very flexible when it comes to the amount of numbers the user can enter in the control.

Bart

r_1gm

  • New Member
  • *
  • Posts: 28
Re: Is there a component like TEdit that only takes numbers in?
« Reply #10 on: June 12, 2012, 08:57:25 am »
How about RX Component TCurrencyEdit ?

sylvanus67

  • New Member
  • *
  • Posts: 25

JD

  • Hero Member
  • *****
  • Posts: 1909
Re: Is there a component like TEdit that only takes numbers in?
« Reply #12 on: June 24, 2012, 06:01:44 pm »
How about RX Component TCurrencyEdit ?

This one does the job. For integer values, just set 'DecimalPlaces' to zero.
Linux Mint - Lazarus 4.0/FPC 3.2.2,
Windows - Lazarus 4.0/FPC 3.2.2

mORMot 2, PostgreSQL & MariaDB.

mandeepmavi

  • New Member
  • *
  • Posts: 10
Re: Is there a component like TEdit that only takes numbers in?
« Reply #13 on: June 29, 2012, 11:11:59 pm »
JD is there any example RX Component TCurrencyEdit. it is giving hard time if i test with negitive number.

mandeepmavi

  • New Member
  • *
  • Posts: 10
Re: Is there a component like TEdit that only takes numbers in?
« Reply #14 on: June 30, 2012, 12:09:01 am »
Unable to multiply price with quantity for total

var
  Price: Double;
begin
    if RadioButton1.Checked then
     begin
     Price := (CurrencyEdit1.Text)  *  StrToFloat(Edit11.Text));
     CurrencyEdit2.Text:=FloatToStr(Price);

Please any idea

 

TinyPortal © 2005-2018