Solved

Delphi Ascii code

Posted on 2013-05-27
2
1,024 Views
Last Modified: 2013-05-28
Hi All:
i've an edit box this edit box for numeric values. i'd like to make this edit box accept just numeric values i wrote on key press  the following

         IF NOT((Key IN ['0' .. '9']) OR (Key = #8) OR (Key = #17)OR (Key = #67)OR (Key = #86) OR (Key = #118)OR (Key = #88)OR (Key = #13)) THEN
                Key := #0;

but this code stop the ctrl+v, ctrl+c and ctrl+x

can you please help me to fix this issue and lets the edit box accept (ctrl+v).
0
Comment
Question by:khaled salem
2 Comments
 
LVL 27

Accepted Solution

by:
Sinisa Vuk earned 500 total points
ID: 39199906
Here it is:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if not (Key in ['0' .. '9', #8, #13]) then
  begin
    //is it ctrl+..
    if HiWord(GetKeyState(VK_CONTROL)) <> 0 then //ctrl down
    begin
      if not (Key in [#3, #22, #24]) then Key := #0; //#3 = CTRL+C, #22 = CTRL+V, #24 = CTRL+X, 
    end
    else
      Key := #0;
  end;
end;

Open in new window

... for comma if number is decimal ... first line should be
if not (Key in ['0' .. '9', #8, #13, #44]) then...

Open in new window


...on torry.net you have lots of numeric edit components already
0
 

Author Closing Comment

by:khaled salem
ID: 39203065
Thanks alot
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi TcxGrid group footer summary 3 353
Using idhttp to login to instagram 2 118
Convert GUI app into console app for Win32 Env 5 125
Multi-layered image in FireMonkey 9 66
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question