Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-10

infinite loop due no OnChange event firing

5 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

In tiOPF with LCL widgetset we hit a little snag. We react to the OnChange event of a TEdit. In GTK1 we have no issues. In GTK2 we get a core dump as soon as the text has changed (first key being pressed). Here is a discussion about the issue between Michael and myself. Michael thinks it's normal, I think it's a bug in LCL.

-------------------------[ forward reply from myself ]------------------

Michael van Canneyt wrote
We looked into this, and it is the mediator design flaw which I told you about: you rely on the fact that setting the text of an edit to the same text will not trigger the OnChange event. Something which I thought you should not rely on.

I still believe this is a bug in the GTK2 (or LCL-GTK2 widgetset). OnChange tells me the value has changed. Setting the Text to the same Text value doesn't change the value, so there is no need to fire the OnChange event.

It is quite normal to have the following in a "setter" method where FValue is the internal storage field and AValue is the new parameter value passed in.

if FValue = AValue then
  Exit;
{ if we got here then something has really changed...}
FValue := AValue.
DoOnChange;    // or whatever else...

---------------------------------[ end ]-----------------------

Like I explained above... Surely there is no need to fire a OnChange event if the TEdit.Text is set to the exact same Value.

eg:

Edit1.Text currently has the value: 'Hello'.

No I do the following...

  Edit1.Text := 'Hello';

I'm assigning the same value to Edit1.Text again... nothing changed, so why must OnChange file? See my example code which is pretty normal code for any setter method and even auto generated by Lazarus IDE.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 7 lines
Hi, In tiOPF with LCL widgetset we hit a little snag. We react to the OnChange event of a TEdit. In GTK1 we have no issues. In GTK2 we get a core dump as soon as the text has changed (first key being pressed). Here is a discussion about the issue between Michael and myself. Michael thinks it's normal, I think it's a bug in LCL.

Small correction: I don't think it is 'normal', but I do think one never should rely on this behaviour :-)

At the very least, all widget sets should react in the same manner: if the TEdit.OnChange event is not fired in GTK 1, it should not fire in Windows or GTK 2 or Mac either.

And the latter is demonstratably not the case now; So this should definitely be fixed.

Michael.

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt
Michael Van Canneyt wrote
Small correction: I don't think it is 'normal', but I do think one never should rely on this behaviour :-)

My apologies... :-)

Show quoted text 6 lines
At the very least, all widget sets should react in the same manner: if the TEdit.OnChange event is not fired in GTK 1, it should not fire in Windows or GTK 2 or Mac either. And the latter is demonstratably not the case now; So this should definitely be fixed.

Agreed!

What is weird is that for the same of being complete, I created three test applications. One TEdit and one TButton. The edit has the text 'Hello' set at design time. The Button's OnClick will assign the value 'Hello' to TEdit. Edit1.OnChange simply does a writeln to the console to show it has fired. Button1.OnClick does a writeln() before and after the call to Edit1. This application was created for fpGUI, LCL-GTK1 and LCL-GTK2. I can't reproduce the error we experienced in tiOPF+LCL applications. Edit1.OnChange doesn't seem to fire now... :-( But it does in tiOPF+LCL apps. :-/

----------- example ----------------
procedure TForm1.FormCreate(Sender: TObject);
begin
  Edit1.OnChange := @EditChanged;
end;
procedure TForm1.EditChanged(Sender: TObject);
begin
  writeln('edit changed');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
  writeln('>> button clicked');
  Edit1.Text := 'Hello1';
  writeln('<< button clicked');
end;

---------------------[ end ]-------------------------

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Graeme Geldenhuys: In tiOPF with LCL widgetset we hit a little snag. We react to the OnChange event of a…
Graeme Geldenhuys wrote
Like I explained above... Surely there is no need to fire a OnChange event if the TEdit.Text is set to the exact same Value.

To explain my reasoning further... The event is called OnChange and not OnSetText. :-)

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys: On Mon, Oct 13, 2008 at 11:05 AM, Michael Van Canneyt My apologies... :-) Agreed! What is…
Graeme Geldenhuys wrote 27 lines
On Mon, Oct 13, 2008 at 11:05 AM, Michael Van Canneyt wrote: > > Small correction: I don't think it is 'normal', but I do think one > never should rely on this behaviour :-) My apologies... :-) > At the very least, all widget sets should react in the same manner: > if the TEdit.OnChange event is not fired in GTK 1, it should not fire > in Windows or GTK 2 or Mac either. > > And the latter is demonstratably not the case now; So this should > definitely be fixed. Agreed! What is weird is that for the same of being complete, I created three test applications. One TEdit and one TButton. The edit has the text 'Hello' set at design time. The Button's OnClick will assign the value 'Hello' to TEdit. Edit1.OnChange simply does a writeln to the console to show it has fired. Button1.OnClick does a writeln() before and after the call to Edit1. This application was created for fpGUI, LCL-GTK1 and LCL-GTK2. I can't reproduce the error we experienced in tiOPF+LCL applications. Edit1.OnChange doesn't seem to fire now... :-( But it does in tiOPF+LCL apps. :-/

IMHO because you should change the exit.text in the edit.onchange event, only then the effect will occur.

Michael.

Reply by email