Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

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
0
tecbuilder
Asked:
tecbuilder
  • 6
  • 5
  • 3
  • +4
1 Solution
 
edeyCommented:
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
 
JaymolCommented:
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
 
tecbuilderAuthor Commented:
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
CrazyOneCommented:
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
 
tecbuilderAuthor Commented:
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
 
kretzschmarCommented:
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
 
CrazyOneCommented:
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
 
JaymolCommented:
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
 
tecbuilderAuthor Commented:
Solution found somewhere else.
0
 
DanRollinsCommented:
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
 
edeyCommented:
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
 
kretzschmarCommented:
agreed
0
 
tecbuilderAuthor Commented:
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
 
CrazyOneCommented:
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
 
edeyCommented:
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
 
tecbuilderAuthor Commented:
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
 
CrazyOneCommented:
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
 
tecbuilderAuthor Commented:
I didn't realize that CrazyOne.
0
 
CrazyOneCommented:
:>)

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
 
MoondancerCommented:
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 5
  • 3
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now