[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Trapping for Ctrl-F4

Posted on 1998-09-07
6
Medium Priority
?
451 Views
Last Modified: 2010-04-06
Hi

I have a MDI applicatin with several child forms. How do I prevent the user from pressing Ctrl-F4 to close the child for (similarly Ctrl-F6 to switch between forms)?

Regards
Keith
0
Comment
Question by:keithcsl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 10

Accepted Solution

by:
viktornet earned 200 total points
ID: 1338903
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (Shift = [ssCtrl])and (key = VK_F4) then
    ShowMessage('Ctrl + F4 was just pressed');
   //Instead of the message do you stuff here
end;
0
 
LVL 1

Author Comment

by:keithcsl
ID: 1338904
victornet

Hi, have you tried your code and got it going? I wrote the exact same code but have failed to trap it. I might be doing it wrong:

In the OnCloseQuery event:
  if flgCannotClose = True then
    CanClose := False;

In the KeyDown event of the form
  if (Shift = [ssctrl]) AND (key = VK_F4) then
    flgCannotClose = True;

Regards
Keith
0
 
LVL 1

Author Comment

by:keithcsl
ID: 1338905
Victornet

I have noticed that the OnCloseQuery is called before the OnKeyDown, that's why I can't trap the Ctrl-F4

It works for Ctrl-F3, etc

Regards
Keith
0
Independent Software Vendors: 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!

 
LVL 10

Expert Comment

by:viktornet
ID: 1338906
Hello Keith =)

Here is what you do......
-----------
var
  flgCannotClose : boolean = False;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  flgCannotClose := True = (Shift = [ssctrl]) AND (key = VK_F4);
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
   if flgCannotClose = True then
     Action := caNone;
end;

procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  flgCannotClose := False;
end;
----------
Regards,
Viktor Ivanov
0
 
LVL 1

Author Comment

by:keithcsl
ID: 1338907
Oh boy, I think it must have been the late nights that have made me a little blind.

Viktornet, thanks to your code above, I have just realised that to avoid the forms from closing, all I have to do is to set
  Action := caNone
in the OnClose event of the form

Thanks a lot

Regards
Keith
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1338908
No prob :-)

Regards,
Viktor Ivanov
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question