Groups > Borland > Delphi winforms controls > Re: A question about edit component




A question about edit component

A question about edit component
28 Jul 2006 23:12:41 -0700
Dear All
Hi,
I have an edit component but I don't want to let user type alphabet in it.it
should be filled by numbers only,how can I prevent from typing alphabets in this
edit.
Post Reply
Re: A question about edit component
29 Jul 2006 07:02:30 -0700
At 15:44:24, 29.07.2006, Marc Rohloff [TeamB] wrote:

> On Sat, 29 Jul 2006 09:39:13 -0400, Marc Rohloff [TeamB] wrote:
> 
> > if key not in ('0'..'9', #8 , #9  )
> >   then key := #0;
> 
> Sorry I didn't realise that this is was a WinForms question.
> The code should be:
>  if e.KeyChar not in ('0'..'9', #8 , #9  )
>    then e.Handled := true;

Er... 

  if not (e.KeyChar in ['0'..'9', #8, #9]) then
    e.Handled := True;

-- 
Rudy Velthuis [TeamB]        http://rvelthuis.de/

"We don't like their sound, and guitar music is on the way out."
Post Reply
Re: A question about edit component
Sat, 29 Jul 2006 09:39:13 -040
On 28 Jul 2006 23:12:41 -0700, Ali wrote:

> I have an edit component but I don't want to let user type alphabet in
it.it should be filled by numbers only,how can I prevent from typing alphabets
in this edit.
> Thanks and regards

Handle the KeyPress event with something like:

if key not in ('0'..'9', #8 , #9  )
  then key := #0;

-- 
Marc Rohloff [TeamB]
Post Reply
Re: A question about edit component
Sat, 29 Jul 2006 09:44:24 -040
On Sat, 29 Jul 2006 09:39:13 -0400, Marc Rohloff [TeamB] wrote:

> if key not in ('0'..'9', #8 , #9  )
>   then key := #0;

Sorry I didn't realise that this is was a WinForms question.
The code should be:
 if e.KeyChar not in ('0'..'9', #8 , #9  )
   then e.Handled := true;


-- 
Marc Rohloff [TeamB]
Post Reply
Re: A question about edit component
Sat, 29 Jul 2006 10:42:47 -040
On 29 Jul 2006 07:02:30 -0700, Rudy Velthuis [TeamB] wrote:

>   if not (e.KeyChar in ['0'..'9', #8, #9]) then
>     e.Handled := True;

It works that way in Oracle <g>

-- 
Marc Rohloff [TeamB]
Post Reply
about | contact