Solved

OnKeyDown event...

Posted on 1998-04-14
7
919 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
Comment Utility
Edited text of question
0
 
LVL 1

Author Comment

by:keithcsl
Comment Utility
Edited text of question
0
 
LVL 1

Expert Comment

by:Edo082297
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:keithcsl
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 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

15 Experts available now in Live!

Get 1:1 Help Now