Solved

How To Trap For Alt-X

Posted on 2001-09-06
20
238 Views
Last Modified: 2010-04-06
I am using D5 in an SDI application.  My main form has a TMenu named mainmenu1.  This form opens a second form via ShowModal.  The main form has a shortcut of Alt-X to close the form.  However, somehow this shortcut has worked it's way over to my second form.  My second form has a TMenu named mainmenu2.  So when I press alt-x both the second and main forms close.  I don't know why this is happening because I have no shortcut key or any key combination defined for the second form and menu.

Does anyone know how to fix this?  If not, how do I trap for the Alt-X?  I tried using the form's onKeyDown event, with KeyPreview = true and also as false and this event seems to get skipped.

Tec
0
Comment
Question by:tecbuilder
  • 6
  • 5
  • 3
  • +4
20 Comments
 
LVL 6

Expert Comment

by:edey
ID: 6461158
Try putting something like this in you menuItem OnClick handler:

if form1.focused then
 application.terminate;

instead of:

application.terminate;

that way you'll close only if form1 is currently active.

GL
Mike
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 6461266
What code do you use to close the modal form?

To be honest, I can't recreate this problem so I think you've done something wrong, rather than it not working correctly.

John.
0
 
LVL 6

Author Comment

by:tecbuilder
ID: 6461362
I have unintentionally created it in several forms.  I have not tried to re-create the problem outside of my current project.  I am using a TActionList on MyMainForm that calls the code below.  In my second form, I use a TMenuItem which calls Close.

I found a work-around solution to be:
if MyMainFrm.Visible then Close;

but this still doesn't solve my problem because I don't always make MyMainForm.Visible := false;

I tried:
if MyMainFrm.Focused then Close;

but the form didn't receive the focus, rather some control did.

Tec
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6461364
I think it would help if we could see your code.

Are you absolutely sure the code handling this is in your main form and not in the Modal Form. Also are you processing anything through the Application.OnMessage event handler? If so this might be were it is happening.


The Crazy One
0
 
LVL 6

Author Comment

by:tecbuilder
ID: 6461402
The code above is all the code I use.  I did forget to specify that the item in the TActionList that calls MyMainForm.Close, has a shortcut of Alt-X.  Also, the second form has MyMainForm in it's uses clause.

I don't use Application.OnMessage anywhere in my program.  To provide more code would be for me to provide the .pas and .dfm files.

Tec
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6461481
i guess the shortcut is resgistered into the windows-os for your application

the tapplication-object has an event onShortCut,
where i guess you could check if the focus is on form1
(and the shortcut itself)

if not, then just set handled to true

let me know if you need a sample

meikl ;-)
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6461526
Hi tecbuilder
As you can see our two comments are just 1 minute apart so when I posted my comment I was unaware of your comment. hehehe.

Any way to test try taking the code out of the action list and putting it the main forms OnKeyDown event and see what happens.
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 6463211
When you get the menu selection (ALT-X) in a child form, use "Self.Close" there and it will not close any other forms.

John.
0
 
LVL 6

Author Comment

by:tecbuilder
ID: 6477604
Solution found somewhere else.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7088893
Hi tecbuilder,
You've requested to delete this question, but its status has remained as 'Pending Delete' because one or more comments have been added.  Normally, the only way to fully delete such a Question is to post a message to Community Support and ask for assistance.

EE is making a one-time database sweep to purge the Pending Delete Questions automatically.  During this sweep:

    tecbuilder -- To allow the deletion to proceed:  Do nothing.
    EXPERTS -- Please DON'T POST a comment except to contest this deletion.

In the future, please refer to http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp#8 for instruction on deleting questions.

DanRollins -- EE database cleanup volunteer
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 6

Expert Comment

by:edey
ID: 7089775
Although tecbuilder was rather vague, and "found his solution elsewhere" I think there was valuable info here, and at the very least the question should be PAQ'ed

GL
Mike
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7090571
agreed
0
 
LVL 6

Author Comment

by:tecbuilder
ID: 7094956
I disagree.  The comments provided didn't work.  Hence where is the valuable information.  If the question was vague, why didn't anyone ask specific questions to help draw the information that you may have needed.  When I posted the question, I could not think of any other information to provide.  We've all been part of Experts-Exchange long enough to know that when people post questions, they don't always post all the information needed in order to get a solution.

DanRollins
You can do as you wish by PAQing this question or not.  I believe that if a question doesn't get a solution, it should not be kept.  The question that should be asked and answered is how to determine the value of the information provided for a solution.  My belief is that value has to be associated to the question.  If information provided did not resolve the question that it has little value.  For example: if I post a solution to a question, but it isn't what the person was needing the solution has no value.  Even though the solution provides good sound information.  I would also be a bit upset if I gave up 30 points to see the solution to this question, only to find there wasn't one, I'd be a bit upset.  Especially if i didn't have many points to use.

A side note: I did follow the correct procedures to have this question deleted.  For whatever reasons, it wasn't.

My 2 cents.
tec
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 7097458
Well tecbuilder maybe you could share with us what was the solution you found. This way the question could be put into the PAQ for future reference and have Community Support refund your points since none of the comments solved the problem for you.
0
 
LVL 6

Expert Comment

by:edey
ID: 7097894
not only that, but just because the info here didn't help you, per say, it doesn't mean that it's worthless. So, again at the very least, this question should be PAQ'ed. As CrazyOne notes it would be better if it was PAQ'ed after you submitted your solution.

GL
Mike
0
 
LVL 6

Author Comment

by:tecbuilder
ID: 7098779
Right now I don't recall what the solution was, nor do I have the time to go back to that project and find it.  (I did make a quick look.)  If EE wants to PAQ a question without a solution that is up to them, but I believe this would be a dis-service to the community.  A PAQed question can be part of a result set when a search is done and I would be upset if I had only a few points available and spent 30 points on a question only to find that there was no solution.  A PAQed question must have a solution not just provide information.

As I said the other day, "The comments provided didn't work.  Hence where is the valuable information."  Who determines what is valuable information and what isn't?  I believe it is the person asking the question.  For this question the information was not valuable, as nothing provided worked.  (I never said the information was worthless, although I will say it was useless as it didn't resolve my problem.)

What is being said here is that a person wanting to know the solution to my question, needs to spend 30 points to find out that in the end there was no solution given and the potential solutions given didn't work as well.  I'm sorry, but I don't see the logic in it.  I have yet to read anyone's comments of the past couple of days, to indicate how the information provided nearly a year ago is valuable to the question.  The outcome of what happens to this and other questions in a similar dillema throughout EE must be associated to the question, because people will be 'expecting' a 'solution' when they pay with their points.

If the experts are so concerned about making sure this unresolved question get PAQed then the points should be reduced to zero, so that no one is charged any points for looking at it.  However, a point to note is that this question has been pending deletion for 9 months and none of the experts who provided comments when the question was active ever said anything after I said I found a solution to my question on 9/12/2001.  Why not?  My thought is that EE doesn't require me to provide my solution to my question.  EE also doesn't provide me any mechanism to PAQ my question without awarding points to anyone and returning my points.  The only option available to me, is to have the question deleted.  My belief is that the experts knew this and the correct process was for having the question deleted.

An additional 3 cents,
tec
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 7099058
Umm tecbuilder I should of been more clear. If you ask Community Support to refund your points and this Q goes into the PAQ it will have a zero point value on it. In other words it won't cost the user any points to view this thread. :>)
0
 
LVL 6

Author Comment

by:tecbuilder
ID: 7099090
I didn't realize that CrazyOne.
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 7099117
:>)

When you ask CS to refund the points make it clear to them that you feel the thread should still be PAQ'd. Usually what will take place is a moderator will come in here make a comment to the nature of why this thread was PAQ'd so others viewing the thread will have an idea of what has taken place with this Question.
0
 
LVL 1

Accepted Solution

by:
Moondancer earned 0 total points
ID: 7099199
Thanks to all.  300 points refunded, item closed by moving to our PAQ at 0 points where it may help others.
Moondancer - EE Moderator
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

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…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

15 Experts available now in Live!

Get 1:1 Help Now