[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 935
  • Last Modified:

OnKeyDown event...

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
keithcsl
Asked:
keithcsl
  • 4
  • 2
1 Solution
 
keithcslAuthor Commented:
Edited text of question
0
 
keithcslAuthor Commented:
Edited text of question
0
 
Edo082297Commented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
keithcslAuthor Commented:
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
 
raunolCommented:
Yes, key:=0 (word) correspond to key:=#0 (char)
also key:=Ord(#0)(word) correspond key:=chr(0);

- Rauno -
0
 
keithcslAuthor Commented:
Rauno

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

Keith
0
 
raunolCommented:
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

Technology Partners: 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!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now