Solved

Delphi Ascii code

Posted on 2013-05-27
2
949 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:khaledsalem
2 Comments
 
LVL 25

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:khaledsalem
ID: 39203065
Thanks alot
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now