?
Solved

OnKeyDown event...

Posted on 1998-04-14
7
Medium Priority
?
931 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
[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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 80 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

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…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

801 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