?
Solved

Trapping for Ctrl-F4

Posted on 1998-09-07
6
Medium Priority
?
455 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
  • 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
Industry Leaders: 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

Technology Partners: 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!

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Integration Management Part 2
Loops Section Overview
Suggested Courses

757 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