Recent

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

xaver13

  • Full Member
  • ***
  • Posts: 111
Hello, I have problem with my application.
 
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.

What should be wrong please? Thank you for help.
--
Jiri Cvrk

lainz

  • Hero Member
  • *****
  • Posts: 4470
    • https://lainz.github.io/
Re: Enter fires application, but also the first EdtBox OnEditingDone event.
« Reply #1 on: October 30, 2016, 01:35:02 pm »
Set the focus to other control on Show event.
« Last Edit: October 30, 2016, 01:47:48 pm by lainz »

xaver13

  • Full Member
  • ***
  • Posts: 111
Re: Enter fires application, but also the first EdtBox OnEditingDone event.
« Reply #2 on: October 30, 2016, 04:21:59 pm »
Set the focus to other control on Show event.

Sorry, it helps not, the event OnEditingDone is still fired (and the field is not correctly fulfilled);
« Last Edit: October 30, 2016, 04:39:13 pm by xaver13 »
--
Jiri Cvrk

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Enter fires application, but also the first EdtBox OnEditingDone event.
« Reply #3 on: October 30, 2016, 04:55:55 pm »
Perhaps something in your app is causing a WMKillFocus message to be sent.
This will trigger OnEditingDone.

xaver13

  • Full Member
  • ***
  • Posts: 111
Re: Enter fires application, but also the first EdtBox OnEditingDone event.
« Reply #4 on: October 30, 2016, 06:02:18 pm »
when I start application using doubleclick on exe it works fine. When I started debugging, it also works fine. Only starting using enter on exe is problematic.
--
Jiri Cvrk

balazsszekely

  • Guest
Re: Enter fires application, but also the first EdtBox OnEditingDone event.
« Reply #5 on: October 30, 2016, 06:11:28 pm »
@xaver13
Please try this:
Code: Pascal  [Select][+][-]
  1.  TForm1 = class(TForm)
  2.     //...
  3.   private
  4.     FNeedToExit: Boolean;
  5.     //...
  6.   end;    
  7.  
  8. //....
  9.  
  10. procedure TForm1.Edit1EditingDone(Sender: TObject);
  11. begin
  12.   if FNeedToExit then
  13.   begin
  14.     FNeedToExit := False;
  15.     Exit;
  16.   end;
  17.   //do something
  18. end;
  19.  
  20. procedure TForm1.FormShow(Sender: TObject);
  21. begin
  22.   FNeedToExit := True;
  23. end;
  24.  

xaver13

  • Full Member
  • ***
  • Posts: 111
Re: Enter fires application, but also the first EdtBox OnEditingDone event.
« Reply #6 on: October 30, 2016, 06:32:33 pm »
@xaver13
Please try this:
Code: Pascal  [Select][+][-]
  1.  TForm1 = class(TForm)
  2.     //...
  3.   private
  4.     FNeedToExit: Boolean;
  5.     //...
  6.   end;    
  7.  
  8. //....
  9.  
  10. procedure TForm1.Edit1EditingDone(Sender: TObject);
  11. begin
  12.   if FNeedToExit then
  13.   begin
  14.     FNeedToExit := False;
  15.     Exit;
  16.   end;
  17.   //do something
  18. end;
  19.  
  20. procedure TForm1.FormShow(Sender: TObject);
  21. begin
  22.   FNeedToExit := True;
  23. end;
  24.  

Now it is working, using enter to fire application,  but ...  where was a problem, now it is hidden?  ;)
Btw. when starting the application using clicking, I now need to try to leave first  field twice ;).

I am using FormActivate
Code: [Select]
unit uStart;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, mysql56conn, sqldb, FileUtil, Forms, Controls, Graphics,
  Dialogs, StdCtrls, LazLogger, IniFiles, uZadavani, uKnihovna;
//LazLoggerDummy  //zaměnit pro zákaz logování


type

  { TFormPrihlaseni }

  TFormPrihlaseni = class(TForm)
    EditKod: TEdit;
    Label1: TLabel;
    MySQLConnection1: TMySQL56Connection;
    Query: TSQLQuery;
    SQLTransaction1: TSQLTransaction;
    procedure EditKodEditingDone(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormShow(Sender: TObject);

  private
    { private declarations }
  public
    { public declarations }
  end;

const
  C_DB_SECTION = 'DB-INFO';

var
  FormPrihlaseni: TFormPrihlaseni;
  jmeno, kod: string;
  priorita: integer;

  INI: TINIFile;
  DBuser, DBpassword, DBlocation: string;

var
  stationID: string;
    FNeedToExit :boolean;
implementation


{$R *.lfm}

{ TFormPrihlaseni }

procedure TFormPrihlaseni.EditKodEditingDone(Sender: TObject);
begin
   if FNeedToExit then
  begin
    FNeedToExit := False;
    Exit;
  end
  else
  begin
  MySQLConnection1.Open;
  if MySQLConnection1.Connected then
  begin
    Query.Database := MySQLConnection1;
    SQLTransaction1.Database := MySQLConnection1;
    Debugln('Connected to server: ' + MySQLConnection1.HostName);
    Query.Close;
    //Prepared statement:
    Query.SQL.Text := 'Select * from D2.Operator where kod = (:KOD)';
    Query.Params.ParamByName('KOD').AsString := EditKod.Text;
    Query.Open;
    while not Query.EOF do
    begin
      (* DbgOut(Query.Fields[0].AsString);
      DbgOut(Query.Fields[1].AsString);
      DbgOut(Query.Fields[2].AsString);
      DbgOut(Query.Fields[3].AsString);
      DbgOut(Query.Fields[4].AsString);
      Debugln(Query.Fields[5].AsString);
      *)
      Debugln('ID: ', Query.FieldByName('ID').AsString,
        ' Operator: ' + Query.FieldByName('Operator').AsString,
        ' Kod: ' + Query.FieldByName('Kod').AsString, ' Skupina: ' +
        Query.FieldByName('Skupina').AsString);
      kod := Query.FieldByName('Kod').AsString;
      jmeno := Query.FieldByName('Operator').AsString;
      priorita := Query.FieldByName('Priorita').AsInteger;
      Query.Next;
      Debugln('Konec dat uživatele');
    end;
    Query.Close;
  end;
  if kod = EditKod.Text then
  begin
    FormZadavani := TFormZadavani.Create(nil);
    FormZadavani.ShowModal;
    FormZadavani.Free;
  end
  else
  begin
    ShowMessage('Uživatel neověřen.');
    Query.Close;
    //Close;
  end;
end;
end;

procedure TFormPrihlaseni.FormActivate(Sender: TObject);
begin
  stationID := GetEnvironmentVariable('COMPUTERNAME') + ' ' +
    GetEnvironmentVariable('USERNAME');
  Debugln('*** Start programu: ' + stationID);
  // Create the object, specifying the the ini file that contains the settings
  INI := TINIFile.Create('DMySQL.ini');
  // Put reading the INI file inside a try/finally block to prevent memory leaks
  try
    // reading values from the INI file.
    DBuser := INI.ReadString(C_DB_SECTION, 'DBuser', '');
    DBpassword := INI.ReadString(C_DB_SECTION, 'DBpassword', '');
    DBlocation := INI.ReadString(C_DB_SECTION, 'DBlocation', '');
  finally
    // After the ini file was used it must be freed to prevent memory leaks.
    INI.Free;
  end;
  Debugln(DBuser + ' ' + DBpassword + ' ' + DBlocation);
  DBpassword := Chrtran(DBpassword, '90m7n8o4pqr1stefgh0ijklu23vwx6yzab5cd',
    '6ab903d1efg8h2ijklm7nop4qrstu5v0wxyz');
  MySQLConnection1.HostName := DBlocation;
  MySQLConnection1.UserName := DBuser;
  MySQLConnection1.Password := DBpassword;
  MySQLConnection1.Transaction := SQLTransaction1;
  MySQLConnection1.DatabaseName := 'D2';
  Debugln('*** Přihlášení ' + RRRRMMDD(now));
  MySQLConnection1.Open;
  if MySQLConnection1.Connected then
  begin
    Query.Database := MySQLConnection1;
    SQLTransaction1.Database := MySQLConnection1;
    Query.Close;
    //Prepared statement:
    Query.SQL.Text := 'Select * from D2.bezi where jmenopoc = (:JMENOPOC)';
    Query.Params.ParamByName('JMENOPOC').AsString := stationID;
    Query.Open;
    while not Query.EOF do
    begin
      Query.Next;
    end;
    if stationID = Query.FieldByName('JMENOPOC').AsString then
    begin
      Query.SQL.Text :=
        'update bezi set ZACATEK= :ZACATEK , BEZI =:BEZI WHERE JMENOPOC = :JMENOPOC ';
      Query.Params.ParamByName('ZACATEK').AsString := RRRRMMDD(Now);
      Query.Params.ParamByName('JMENOPOC').AsString := stationID;
      Query.Params.ParamByName('BEZI').AsString := 'A';
      Query.execSQL;
      SQLTransaction1.commitretaining;
    end
    else
    begin
      Query.SQL.Text :=
        'insert into bezi (ID,JMENOPOC,ZACATEK,BEZI)' +
        'values((:ID),(:JMENOPOC),(:ZACATEK),(:BEZI))';
      Query.Params.ParamByName('JMENOPOC').AsString := stationID;
      Query.Params.ParamByName('ZACATEK').AsString := RRRRMMDD(Now);
      Query.Params.ParamByName('BEZI').AsString := 'A';
      Query.execSQL;
      SQLTransaction1.commitretaining;
    end;
    Query.Close;
  end;
end;

procedure TFormPrihlaseni.FormDestroy(Sender: TObject);
begin
  Query.Close;
  //Prepared statement:
  Query.SQL.Text := 'Select * from D2.bezi where jmenopoc = (:JMENOPOC)';
  Query.Params.ParamByName('JMENOPOC').AsString := stationID;
  Query.Open;
  while not Query.EOF do
  begin
    Query.Next;
  end;
  if stationID = Query.FieldByName('JMENOPOC').AsString then
  begin
    Query.SQL.Text :=
      'update bezi set ZACATEK= :ZACATEK , BEZI =:BEZI WHERE JMENOPOC = :JMENOPOC ';
    Query.Params.ParamByName('ZACATEK').AsString := RRRRMMDD(Now);
    Query.Params.ParamByName('JMENOPOC').AsString := stationID;
    Query.Params.ParamByName('BEZI').AsString := 'N';
    Query.execSQL;
    SQLTransaction1.commitretaining;
  end;
  Query.Close;
end;

procedure TFormPrihlaseni.FormShow(Sender: TObject);
begin
    FNeedToExit := True;
end;


end.                                 
« Last Edit: October 30, 2016, 06:52:17 pm by xaver13 »
--
Jiri Cvrk

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Enter fires application, but also the first EdtBox OnEditingDone event.
« Reply #7 on: October 30, 2016, 06:59:54 pm »
I can confirm the issue.
It also happens when you launch from console.

Can you please report it to the bugtracker and attach a minimal test case (1 form, 2 TEdits, assign OnEditingDone and set ActiveControl to the TEdit).

I think it is a regression.

Could anyone test with 1.4.x or 1.2.x version, I don't have them anymore.

Bart

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Enter fires application, but also the first EdtBox OnEditingDone event.
« Reply #8 on: October 31, 2016, 11:59:35 pm »
...a minimal test case (1 form, 2 TEdits, assign OnEditingDone and set ActiveControl to the TEdit).
...
Could anyone test with 1.4.x or 1.2.x version, I don't have them anymore.
Event not fired on startup with 1.4.2

totya

  • Hero Member
  • *****
  • Posts: 720
Re: Enter fires application, but also the first EdtBox OnEditingDone event.
« Reply #9 on: November 01, 2016, 12:44:06 am »
Event not fired on startup v1.6 too (Win x64).

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. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Edit1: TEdit;
  16.     Edit2: TEdit;
  17.     Memo1: TMemo;
  18.     procedure EditEditingDone(Sender: TObject);
  19.     procedure FormCreate(Sender: TObject);
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.lfm}
  28.  
  29. { TForm1 }
  30.  
  31. procedure TForm1.FormCreate(Sender: TObject);
  32. begin
  33.   Edit1.OnEditingDone:= @EditEditingDone;
  34.   Edit2.OnEditingDone:= @EditEditingDone;
  35.  
  36.   ActiveControl:= Edit1;
  37. end;
  38.  
  39. procedure TForm1.EditEditingDone(Sender: TObject);
  40. begin
  41.   Memo1.Lines.Add('TEdit EditingDone events fired:'+(Sender as TEdit).Name);
  42. end;
  43.  
  44. end.
  45.  
« Last Edit: November 01, 2016, 09:09:53 pm by totya »

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Enter fires application, but also the first EdtBox OnEditingDone event.
« Reply #10 on: November 01, 2016, 02:43:28 pm »
Event not fired on startup with 1.4.2

Please report in bugtracker and clearly state it is a regression.

Bart

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Enter fires application, but also the first EdtBox OnEditingDone event.
« Reply #11 on: November 01, 2016, 06:47:21 pm »
I can reproduce the error in 1.6 fixes (soon to be 1.6.2).
So, it would be nice to be fixed before the next release.

Bart

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Enter fires application, but also the first EdtBox OnEditingDone event.
« Reply #12 on: November 01, 2016, 07:05:25 pm »
Reported as Issue 30836.

Bart

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: Enter fires application, but also the first EdtBox OnEditingDone event.
« Reply #13 on: November 01, 2016, 07:09:46 pm »
"Brute force" fix, maybe: Don't process OnEditingDone while control is loaded (Could have side-effects, though)
Code: Pascal  [Select][+][-]
  1. procedure TControl.EditingDone;
  2. begin
  3.   if (csLoading in ComponentState) then exit;  // <-- new
  4.   if Assigned(OnEditingDone) then OnEditingDone(Self);
  5. end;

Bart

  • Hero Member
  • *****
  • Posts: 5290
    • Bart en Mariska's Webstek
Re: Enter fires application, but also the first EdtBox OnEditingDone event.
« Reply #14 on: November 01, 2016, 07:29:34 pm »
"Brute force" fix, maybe: Don't process OnEditingDone while control is loaded (Could have side-effects, though)

When the event is fired ComponentState = [].
So, this will not do.

Bart

 

TinyPortal © 2005-2018