Fay Kalyus
2004-01-31 16:39:09 UTC
Using RichEdit, I am creating a file viewer and I would like to allow users
to backtrack to a previous point. Following the logic of web browsers, I
would like to use the backspace key for this, and have it work whether or
not the RichEdit control has focus.
Accordingly, then, I set the form's KeyPreview property to True and did
something like this:
procedure TMyForm.FormKeyPress(Sender: TObject; var Key: Char);
begin
case Ord(Key) of
8 : DoSomeStuff; { Backspace key }
13 : DoSomeOtherStuff; { Enter key }
27 : Close; { Esc key closes the window }
6,70,102 : DoFind; { Ctrl-F or F and Shift-F }
end;
Key := #0; { Attempt to destroy to the key }
end;
For the most part, this works perfectly! Unfortunately, after I trap and
act on the Backspace (decimal character #8) in FormKeyPress, Delphi merrily
passes the #8 to RichEdit, which beeps (since ReadOnly is set to True). It
doesn't notice that I set Key to #0.
Even stranger: setting the Key to #0 works fine for all of the other keys.
What works for character #6 (Ctrl-F) doesn't work for character #8.
Apparently it is a "special case".
I also tried resetting the Key value in the KeyPress and KeyUp procedures
for the form and in RichEdit. It didn't help.
My question, then, is this ...
How can I get a form to detect a key, then tell Windows to forget about it?
to backtrack to a previous point. Following the logic of web browsers, I
would like to use the backspace key for this, and have it work whether or
not the RichEdit control has focus.
Accordingly, then, I set the form's KeyPreview property to True and did
something like this:
procedure TMyForm.FormKeyPress(Sender: TObject; var Key: Char);
begin
case Ord(Key) of
8 : DoSomeStuff; { Backspace key }
13 : DoSomeOtherStuff; { Enter key }
27 : Close; { Esc key closes the window }
6,70,102 : DoFind; { Ctrl-F or F and Shift-F }
end;
Key := #0; { Attempt to destroy to the key }
end;
For the most part, this works perfectly! Unfortunately, after I trap and
act on the Backspace (decimal character #8) in FormKeyPress, Delphi merrily
passes the #8 to RichEdit, which beeps (since ReadOnly is set to True). It
doesn't notice that I set Key to #0.
Even stranger: setting the Key to #0 works fine for all of the other keys.
What works for character #6 (Ctrl-F) doesn't work for character #8.
Apparently it is a "special case".
I also tried resetting the Key value in the KeyPress and KeyUp procedures
for the form and in RichEdit. It didn't help.
My question, then, is this ...
How can I get a form to detect a key, then tell Windows to forget about it?