Recent

Author Topic: Enter fires application, but also the first EdtBox OnEditingDone event.  (Read 10064 times)

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: Enter fires application, but also the first EdtBox OnEditingDone event.
« Reply #15 on: November 01, 2016, 08:00:11 pm »
Strange: even if I remove the line added the bug does not appear again (Laz trunk/fpc 3.0, Laz 1.6/fpc 3.0, Laz trunk/fpc trunk)

Ondrej Pokorny

  • Full Member
  • ***
  • Posts: 220
Re: Enter fires application, but also the first EdtBox OnEditingDone event.
« Reply #16 on: November 01, 2016, 08:36:46 pm »
Well it's not really a bug but a "feature". Windows Explorer / Total Commander executes the application in KeyDown and the KeyUp event is handled by the executed Lazarus application. And EditingDone is fired upon KeyUp.

The only right workaround is to check for an existing ENTER-KeyDown. If not present, don't fire EditingDone.

Ondrej Pokorny

  • Full Member
  • ***
  • Posts: 220
Re: Enter fires application, but also the first EdtBox OnEditingDone event.
« Reply #17 on: November 01, 2016, 08:46:59 pm »
The only right workaround is to check for an existing ENTER-KeyDown. If not present, don't fire EditingDone.

Hmmm, OnKeyDown is fired as well, so there won't be any easy workaround :(

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Enter fires application, but also the first EdtBox OnEditingDone event.
« Reply #18 on: November 01, 2016, 10:07:02 pm »
Hmmm, OnKeyDown is fired as well, so there won't be any easy workaround :(

AFAICS only a WM_KEYUP message is sent to the Edit:

WM_KEYUP received for window 001104DE
TWinControl.KeyUpBeforeInterface -->Edit1:TEdit.KeyUp()
Edit1KeyUp: 13
TWinControl.WMKeyUp Edit1:TEdit
TWinControl.DoRemainingKeyUp Edit1:TEdit
TCustomEdit.KeyUpAfterInterface
TWinControl.KeyUpAfterInterface Edit1:TEdit
TCustomEdit.KeyUpAfterInterface calling EditingDone
TForm1.Edit1EditingDone: Sender is Edit1Handle=001104DE

This it what happens when user presse Enter:

Edit1KeyDown: 13
Edit1KeyPress: #13
WM_KEYUP received for window 001104DE
TWinControl.KeyUpBeforeInterface -->Edit1:TEdit.KeyUp()
Edit1KeyUp: 13
TWinControl.WMKeyUp Edit1:TEdit
TWinControl.DoRemainingKeyUp Edit1:TEdit
TCustomEdit.KeyUpAfterInterface
TWinControl.KeyUpAfterInterface Edit1:TEdit
TCustomEdit.KeyUpAfterInterface calling EditingDone
TForm1.Edit1EditingDone: Sender is Edit1Handle=001104DE

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Enter fires application, but also the first EdtBox OnEditingDone event.
« Reply #19 on: November 01, 2016, 10:07:57 pm »
Let's continu on bugtracker only from now.

Bart

totya

  • Hero Member
  • *****
  • Posts: 720
Re: Enter fires application, but also the first EdtBox OnEditingDone event.
« Reply #20 on: November 01, 2016, 10:09:50 pm »
I'm sorry, I see this problem now. Lazarus 1.6 and Win x64. OMG... Enter = Enter KEY

Windows only solution:

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.  
  10.   LCLIntf, LCLType, Windows;
  11.  
  12. type
  13.  
  14.   { TForm1 }
  15.  
  16.   TForm1 = class(TForm)
  17.     Edit1: TEdit;
  18.     Edit2: TEdit;
  19.     Memo1: TMemo;
  20.     procedure FormCreate(Sender: TObject);
  21.     procedure FormActivate(Sender: TObject);
  22.     procedure EditEditingDone(Sender: TObject);
  23.   private
  24.     FormActivated: boolean;
  25.   end;
  26.  
  27. var
  28.   Form1: TForm1;
  29.  
  30. implementation
  31.  
  32. {$R *.lfm}
  33.  
  34. { TForm1 }
  35.  
  36. procedure TForm1.FormCreate(Sender: TObject);
  37. begin
  38.   FormActivated:= false;
  39.  
  40.   Edit1.OnEditingDone:= @EditEditingDone;
  41.   Edit2.OnEditingDone:= @EditEditingDone;
  42.  
  43.   ActiveControl:= Edit1;
  44. end;
  45.  
  46. procedure TForm1.FormActivate(Sender: TObject);
  47.  
  48.   // https://groups.google.com/forum/#!topic/borland.public.delphi.objectpascal/1SvTc9nX4Z4
  49.   procedure EmptyKeyQueue;
  50.   var
  51.     Msg: TMsg;
  52.   begin
  53.     while PeekMessage(Msg{%H-}, 0, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE or PM_NOYIELD)
  54.       do Application.ProcessMessages;
  55.   end;
  56.  
  57. var
  58.   s: string;
  59. begin
  60.   if not(FormActivated) then
  61.   begin
  62.     s:= Caption;
  63.  
  64.     Refresh; // form paint..
  65.  
  66.     try
  67.       while GetKeyState(vk_RETURN) < 0 do
  68.       begin
  69.         if Caption = s then
  70.           Caption:= s+ ' - app start is suspended, because ENTER key is pressed!';
  71.  
  72.         EmptyKeyQueue;
  73.  
  74.         Sleep(20); // low CPU usage...
  75.       end;
  76.  
  77.     finally
  78.       Caption:= s;
  79.       FormActivated:= true;
  80.     end;
  81.   end;
  82. end;
  83.  
  84. procedure TForm1.EditEditingDone(Sender: TObject);
  85. begin
  86.   Memo1.Lines.Add('TEdit EditingDone events fired:'+(Sender as TEdit).Name);
  87. end;
  88.  
  89. end.
  90.  

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Enter fires application, but also the first EdtBox OnEditingDone event.
« Reply #21 on: November 01, 2016, 10:23:06 pm »
Just for the record. If i keep my enter key pressed e.g. not lift it when pressing enter then also 1.4.2 shows this behaviour. But what is to be expected there ? Usually one pressed enter and leave the key alone. It is not strange that when i keep it pressed and wait for the form to appear that the event gets fired ?

The only problem i can see with that is that some machines are faster with executing an app than others so on a fast machine you will encounter tis situation quicker.

If you'd ike to avoid that then the keyboard buffer should be cleared before lcl kicks in ?

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Enter fires application, but also the first EdtBox OnEditingDone event.
« Reply #22 on: November 01, 2016, 10:35:20 pm »
@ All: please move discussion/suggestions to the bugtracker.

totya

  • Hero Member
  • *****
  • Posts: 720
Re: Enter fires application, but also the first EdtBox OnEditingDone event.
« Reply #23 on: November 03, 2016, 01:35:23 am »
Strange behaviour is, that when I run this application using enter from windows explorer (Total Commander, Free Commander) the application runs, but also fires the On Editing Done event on first EdtBox immediatelly.

Hi!

Until the permanent solution arrives in next (svn?) Lazarus version, I suggest try my code from here. It's works for me. Or see the attached file here. Windows only!


 

TinyPortal © 2005-2018