Search the Community
Showing results for tags 'form'.
Found 2 results
-
I want to show a confirmation question before closing the main form by clicking on the "x" in the upper right corner. The following is based on Delphi help, the example given in a link in tform.OnCloseQuery help. It used to work in another program but it doesn't work in my current program. I put "procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);" in the form's class. Then I have this, based on the example: procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin if MessageDlg( 'Do you want to exit the program?', mtConfirmation, [mbYes, mbCancel], 0) = mrCancel then CanClose := false; end; The program starts and then I click a button to start some tasks. If I click on the "x" before the tasks are started, it closes immediately. If I do it after the tasks have started, it closes immediately if it is running from the EXE. If it is running from the IDE, it gives an access violation. What do I need to do to make it behave as intended (i.e. confirm before closing the form.)
-
I have a hotkey config dialog which responds to key presses by jumping to that key in a list and focusing it for editing. The user must first press "Find Key" and then select a key in order to edit it (but, I'm seriously considering removing this button altogether and just have the dialog always listen for key presses). Problem is, if they hit [Space], this clicks the "Find Key" button again. Space is focused for editing, no problem, but the "Press any key to edit..." label is shown instead of "Editing key: Space." This could cause potential confusion for the end-user. Similarly, hitting [Enter] doesn't focus Enter for editing, which is a bit frustrating but I'm not sure what I can do about that. Not looking to restructure/rewrite the unit or change the way that the app handles reading/writing key names, etc. I just want to know if there's a simple way to stop the Space bar from auto-clicking the "Find Key" button. Tried "if Key = VK_SPACE then Exit;" on the form's OnKeyDown event handler and on the [btnFindKey] OnKeyDown event handler and similar things like that, nothing seems to work. --- As an aside, if I can't find a way to get the dialog to always listen for key presses without first pressing "Find Key", then ideally it'd be better if FindKey must be pressed in order to focus any key for editing. At the moment, it's sometimes possible to press a few keys after hitting "Find Key" and each one will be focused, but then some won't be. I can't figure out what's causing this behaviour, but if there's a way to stop the form from listening for key presses once one has been focused in the list, that would also be something of an improvement.