Solved

Trapping for Ctrl-F4

Posted on 1998-09-07
6
417 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 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now