Solved

OnKeyDown event...

Posted on 1998-04-14
7
921 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Internet Explorer View Settings Question 15 105
how to center only a line in richedit? 4 52
Reconfigure Delphi Install? 2 45
Convert a string into a TDateTime 5 50
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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
CodeTwo Sync for iCloud (http://www.codetwo.com/sync-for-icloud?sts=6554) automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

911 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

22 Experts available now in Live!

Get 1:1 Help Now