OnKeyPress Event

Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2007
Posts: 6
Reputation: docdoc is an unknown quantity at this point 
Solved Threads: 0
docdoc docdoc is offline Offline
Newbie Poster

OnKeyPress Event

 
0
  #1
Jun 12th, 2007
Can anyone explain why the OnKeyPress Event does not work with a TButton on the same Form. What am I doing wrong?

procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption:='button';
end;

procedure TForm1.KeyPress(Sender: TObject; var Key: Char);
begin
if Key='a' then Label1.Caption:='OK';
end;
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 27
Reputation: Terry Robinson is an unknown quantity at this point 
Solved Threads: 1
Terry Robinson Terry Robinson is offline Offline
Light Poster

Re: OnKeyPress Event

 
0
  #2
Jun 12th, 2007
You need to set the Form's KeyPreview property to True before you can capture keyboard events.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 6
Reputation: docdoc is an unknown quantity at this point 
Solved Threads: 0
docdoc docdoc is offline Offline
Newbie Poster

Re: OnKeyPress Event

 
0
  #3
Jun 13th, 2007
Thanks...it's easy when you know how. I'm just started to teach myself...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Pascal and Delphi
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC