Disabling the BackSpace key


Please help...

How do I disable the backspace key? I want to disregard the backspace key at certain times in my application.

Many thanks.
Little_NikkiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LischkeCommented:
That's quite easy. Set the form's KeyPreview to True and write an key down handler where you can reject specific keys:

procedure TMainForm.FormKeyPress(Sender: TObject; var Key: Char);

begin
  if Key = #8 then
  begin
    Key := #0;
    Close;
  end;
end;


Ciao, Mike
0
LischkeCommented:
Ooops, sorry, you should of course avoid calling Close :-) (I copied the sample from an ESC key handler where I want to close the form). Just set Key to #0 that's all.

Ciao, Mike
0
BSamsonCommented:
Set up an Event handler for KeyPress on your form and put some code like this in

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = Char(8) then
    Key := Char(0);
end;

Now, when you want to activate this code, set Form1.KeyPreview := True;

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

BSamsonCommented:
Ooops, Sorry Mike

You're a much faster typist than me. I was typing my answer as you posted your comment up.

Please reject my answer as it's identical to Mikes.

Brian
0
craig_capelCommented:
before i post a question up.... how possible is it do the same thing as dos did, hook on to int 9, keyboard int vector and then disable the backspace....or is this simply not possible because its windows?

if you think its possible, i will post up a question.....
0
LischkeCommented:
Hi Craig,

no, hooking an interrupt vector is not possible any longer. You should really get used that a system has total control of your machine (and it's not only Windows, but each modern operating system).

Ciao, Mike
0
Little_NikkiAuthor Commented:
Thank you so much! You've been a big help.
Til next time =)
0
LischkeCommented:
Nikki, if you wanna have a next time then please look more carefully who you give the points!

BSamson, now you know why I'm so often complaining about proposing an answer by default. Please, use only comments in the future...

Ciao, Mike
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.