Link to home
Start Free TrialLog in
Avatar of tecbuilder
tecbuilder

asked on

How To Trap For Alt-X

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
Avatar of edey
edey

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
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.
Avatar of tecbuilder

ASKER

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
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
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
Avatar of kretzschmar
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 ;-)
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.
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.
Solution found somewhere else.
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 https://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp#8 for instruction on deleting questions.

DanRollins -- EE database cleanup volunteer
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
agreed
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
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.
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
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
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. :>)
I didn't realize that CrazyOne.
:>)

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.
ASKER CERTIFIED SOLUTION
Avatar of Moondancer
Moondancer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial