Solved

Trapping for Ctrl-F4

Posted on 1998-09-07
6
437 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 50 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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

728 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