943,989 Members | Top Members by Rank

Ad:
Jun 12th, 2007
0

OnKeyPress Event

Expand Post »
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;
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
docdoc is offline Offline
8 posts
since Jun 2007
Jun 12th, 2007
0

Re: OnKeyPress Event

You need to set the Form's KeyPreview property to True before you can capture keyboard events.
Reputation Points: 12
Solved Threads: 1
Light Poster
Terry Robinson is offline Offline
27 posts
since Apr 2007
Jun 13th, 2007
0

Re: OnKeyPress Event

Thanks...it's easy when you know how. I'm just started to teach myself...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
docdoc is offline Offline
8 posts
since Jun 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Pascal and Delphi Forum Timeline: On MouseHover events?
Next Thread in Pascal and Delphi Forum Timeline: Would someone be willing to point me to a good reference on how to use the IdFTP?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC