Recent

Author Topic: tfloatspinedit always executes "oneditingdone" event for all other buttons  (Read 5116 times)

jkorten

  • New Member
  • *
  • Posts: 20
So I am not yet comfortable with Lazarus. But here's a simple app. Put in a tfloatspinedit and a tspeedbutton: for the tfloatspinedit object double click on the event "oneditingdone" and put in showmessage('spin'), and double click on the event "onclick" for the speed button and put showmessage('button');

run

change the value in the floatspinedit box to something (a number) and hit return. Now any other button you press will execute the tfloatspineditoneditingdone event.

Why is this? Is there some type of acknowledgement I'm supposed to execute to get the tfloatspinedit guy to stop triggering?

The regular tspinedit does not exhibit this behavior by the way.

Thanks in advance for the help.

jkorten

  • New Member
  • *
  • Posts: 20
Re: tfloatspinedit always executes "oneditingdone" event for all other buttons
« Reply #1 on: December 19, 2011, 11:13:56 pm »
my mistake - tspinedit does this too

jkorten

  • New Member
  • *
  • Posts: 20
Re: tfloatspinedit always executes "oneditingdone" event for all other buttons
« Reply #2 on: December 20, 2011, 03:37:49 am »
OK let me be more plain. I do not understand why the program mentioned above will always enter the spinedit "editingdone" event even if I press the speedbutton.

The relevant events are listed below and only the spinedit1 event is triggered even if you press the speedbutton. There must be an "event edit done" property that I have to set but I can't find it in the documentation.


procedure TForm1.SpinEdit1EditingDone(Sender: TObject);
begin
  showmessage('spin');
  form1.setfocus;
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
  showmessage('button');
end;


wp

  • Hero Member
  • *****
  • Posts: 13327
Re: tfloatspinedit always executes "oneditingdone" event for all other buttons
« Reply #3 on: December 20, 2011, 09:14:13 am »
Use a regular TButton or TBitBtn instead of the TSpeedbutton which is not a TWinControl and cannot receive the focus.
« Last Edit: December 20, 2011, 09:23:06 am by wp »

jkorten

  • New Member
  • *
  • Posts: 20
Re: tfloatspinedit always executes "oneditingdone" event for all other buttons
« Reply #4 on: December 20, 2011, 01:53:56 pm »
Thanks for the suggestion WP but when I put the following code in (with a regular button) still the spinedit1 event fires twice (even when disabled?) before I can get focus onto the regular button.

Clearly there must be a crossed wire in the way this object triggers events, no?

Is there anything I am missing about acknowledging the event within the event handler?

example code below:


procedure TForm1.SpinEdit1EditingDone(Sender: TObject);
begin
  spinedit1.Enabled:= false;
  showmessage('spin');
  button1.SetFocus;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  showmessage('button2');
  spinedit1.enabled := true;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  showmessage('form');
end;

wp

  • Hero Member
  • *****
  • Posts: 13327
Re: tfloatspinedit always executes "oneditingdone" event for all other buttons
« Reply #5 on: December 20, 2011, 03:46:51 pm »
I'm not quite sure, but I think to see in the source code of the component that the OnEditingDone event really fires twice: first, when ENTER is pressed (that's hard-coded into TCustomEdit), and second when the Edit loses focus (inherited from TControl). Since your OnEditingDone shows a messagebox the edit automatically loses focus. If you want to check the behavior of the event add a silent watch, for example a counter that you increment in the OnEditingDone and display in a label.

If you really need the message dialog, you could try the following work-around: add a status variable to the form and keep track of the EditingDone's:

Code: [Select]
var
  EditDoneCounter: integer;

In the Edit's OnChange event handler you reset the counter, and in the OnEditDoneEvent you increment it. The main code of the OnEditDone event should be executed only while EditDoneCounter=0.

Something like this (of course, untested...)

Code: [Select]
procedure TForm1.SpinEditChange(Sender:TObject);
begin
  EditDoneCounter := 0;
end;

procedure TForm1.SpinEditEditingDone(Sender:TObject);
begin
  if EditDoneCounter = 0 then begin
    // here is was you want to do, e.g. show the messge box
  end;
  inc(EditDoneCounter);
end;
« Last Edit: December 20, 2011, 11:00:54 pm by wp »

jkorten

  • New Member
  • *
  • Posts: 20
Re: tfloatspinedit always executes "oneditingdone" event for all other buttons
« Reply #6 on: December 21, 2011, 08:28:13 pm »
Well the only workaround I found was to use a tedit object and it fires only once on editingdone. I put in my own string checking.

Both of the tspinedit and tfloatspinedit objects cause all other object events to trigger through  the oneditingdone event for the spinedit objects.

I regard this as a bug. Especially since nobody else has seen this behavior (and said so).

Should I report this?

wp

  • Hero Member
  • *****
  • Posts: 13327
Re: tfloatspinedit always executes "oneditingdone" event for all other buttons
« Reply #7 on: December 22, 2011, 01:34:00 am »
Yes.

 

TinyPortal © 2005-2018