Solved

Delphi Ascii code

Posted on 2013-05-27
2
1,010 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 26

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
Convert Jpg /PNG To GIF 5 150
Best Firemonkey component pack 1 119
Delphi 2 69
Installshield for Embarcadero EX 10.1 Berlin 4 60
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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

856 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