Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IWButtons Hotkey property and the &-sign in Captions
#7
Hi All,

I thought this was all done, sealed and bagged, but no. There is a problem with the Escape key handling, I do not quite get:

I have a form, IWForm1, with some edit fields and 2 buttons. One to save the data, and one to discard editing and release the form.

When pressing F10, the Button BTNGEM.onclick is executed and correctly checks for possible errors in editfields, before saving. If any, saving is discarded with a message and otherwise the data is saved. The form stays open with all data still in the edit fields. This part is working correctly both with F10 and when clicking the button with the mouse.

When pressing ESC, the button BTNAFD.onclick is executed and checks for any changes. If no changes, the form is released. if any changes though, it shows a warning dialog: "you have changed data. do you want to save before leaving ?" with a yes/no option. if user selects no, then changes are is discarded and the form is released. If the users selects yes, the data is saved and the form is released.

Pressing ESC do go through all the tests, but do not show the warning (not even just a simple Webapplication.showmessage I tried instead) whereas it do work correctly when clicking the Button BTNAFB with the mouse. Debugging as far as I can, it do execute the ShowWarning line, but never show the warning. It is like the ESC value / default behaviour, is sent to the warning dialog, which automatically selects no and terminates, even before the warning dialog was rendered(or at least so quick I do not see the dialog appear).

If it is the ESC value being sent on to further processing, is there a way to stop the keyhandling as part of the onkeydown event ?

Or do any of you have an answer to what is causing the behaviour ? As you can see from the JS code, I'm trying to avoid further handling, but it appears not to be successful.

Below is the code I am using:

In the Form.Javascript I have the following lines:

window.addEventListener("keydown", function (event)
{
  if (event.defaultPrevented)
  {
    return; // Do nothing if the event was already processed
  }
  switch (event.keyCode)
  {
    case 121:
      event.returnValue = false;
      event.keyCode = 0;
      $("#BTNGEM").click();
      break;
    case 27:
      event.returnValue = false;
      event.keyCode = 0;
      $("#BTNAFB").click();
      break;
    default:
      return;
  }
  event.preventDefault();
},
true);


and on the form, I have to two buttons with the following OnClick events:

procedure TIWForm1.BtnAfbClick(Sender: TObject);
begin
  if DataChanged then
  begin
    ShowVarning; 
  end else
  begin
    Release;
  end;
end;

procedure TVedlVognF.BtnGemClick(Sender: TObject);
begin
  if IWEdit1.Text = '' then
  begin   
    Webapplication.ShowMessage('Error: You must fill in the name field !');
  end else
  begin
    dm.SaveData;
  end;
end;


Regards
Soren

Hi all again,

I have solved the problems as described above:

By Adding a SLEEP function:

function sleep(delay)
{
  var start = new Date().getTime();
  while (new Date().getTime() < start + delay);
}


and calling it with 100 ms as delay, just before executing the $("#BTNAFB").click() event in the keydown function:

case 27:
  event.returnValue = false;
  event.keyCode = 0;
  sleep(100);
  $("#BTNAFB").click();
  break;


Now, pressing ESC do execute the warning and correctly responds to the users choice. 

A small delay in time, but with a huge impact on program execution, not to mention wasted development time <G>

Regards
Soren
Reply


Messages In This Thread
IWButtons Hotkey property and the &-sign in Captions: Problem! - by SorenJensen - 09-21-2019, 08:29 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)