Solved

OnKeyDown event...

Posted on 1998-04-14
7
922 Views
Last Modified: 2012-06-22
Hi

For the OnKeyPress event, the Key can be set to Null, ie #0 to cancel the keypress. For the OnKeyDown event, what value do i set the Key if i want to cancel the keydown?

Cheers
Keith
0
Comment
Question by:keithcsl
  • 4
  • 2
7 Comments
 
LVL 1

Author Comment

by:keithcsl
ID: 1361508
Edited text of question
0
 
LVL 1

Author Comment

by:keithcsl
ID: 1361509
Edited text of question
0
 
LVL 1

Expert Comment

by:Edo082297
ID: 1361510
Hi Keithcsl

   You can "cancel" any event by setting the method pointer to nil like this:

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form1.OnMouseDown := nil;
end;

Then later on you can "reactivate" the event:

procedure TForm1.Button2Click(Sender: TObject);
begin
  Form1.OnMouseDown := Form1.FormMouseDown;
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
   showmessage ('hello');
end;

Regards,

Edo

P.S. This isn't the greatest programming practice; you should code for whether or not the event's code should be executed; otherwise, you (or the person who has to modify the code) will end up with a hard to trace bug :)


0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 1

Author Comment

by:keithcsl
ID: 1361511
Edo

i am sorry but I should have structured my question more clearly. My intention is not to cancel the event, but rather trap the event, cancel the original Key and run my process.  For example in the OnKeyDown event,

  if (Key = 13) then
  begin
    // Set new Key here, maybe Key := 0
    RunProcedure;
  end;

PS: I have found setting Key := 0 does the job, but is it correct to do so??

Keith
0
 

Expert Comment

by:raunol
ID: 1361512
Yes, key:=0 (word) correspond to key:=#0 (char)
also key:=Ord(#0)(word) correspond key:=chr(0);

- Rauno -
0
 
LVL 1

Author Comment

by:keithcsl
ID: 1361513
Rauno

Hmm, why didn't I think of checking it like that? Thanks. Could you post ur comment as an answer?

Keith
0
 

Accepted Solution

by:
raunol earned 20 total points
ID: 1361514
Hi, Keith

>Hmm, why didn't I think of checking it like that?

Sometimes known for me, too ;-)

> Could you post ur comment as an answer?

Well, that wasn't very proper answer for Your
original question. But..
..my expert score is still zerou.. ;-) ;-)
So, if You will, here You are:

Yes, key:=0 (word) correspond to key:=#0 (char)
also key:=Ord(#0)(word) correspond key:=chr(0);

- Rauno -
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi component that can load a DLL in design time? 8 64
Help on project with Soap 10 54
Delphi Firemonkey Need Sample for Online Shopping Example. 2 142
Magic Software info 18 130
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 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