Solved

Delphi Ascii code

Posted on 2013-05-27
2
1,091 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Suggested Courses
Course of the Month6 days, 12 hours left to enroll

623 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