Recent

Author Topic: TSpinEdit possible bug  (Read 3658 times)

Bart

  • Hero Member
  • *****
  • Posts: 4475
    • Bart en Mariska's Webstek
Re: TSpinEdit possible bug
« Reply #15 on: October 03, 2021, 10:03:22 am »
Bart, I have no time to post a Bug report because it seems to go no where in any case.

Well, given my replies in this thread, I don't really see how you came to that conclusion.

Bart

wp

  • Hero Member
  • *****
  • Posts: 8897
Re: TSpinEdit possible bug
« Reply #16 on: October 03, 2021, 10:36:08 am »
Bart, I have no time to post a Bug report because it seems to go no where in any case.
Is it this closed one: https://gitlab.com/freepascal.org/lazarus/lazarus/-/issues/38388? Your patch was applied, and you were asked whether it works, and you confirmed. So, what are you complaining about?
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Bart

  • Hero Member
  • *****
  • Posts: 4475
    • Bart en Mariska's Webstek
Re: TSpinEdit possible bug
« Reply #17 on: October 03, 2021, 12:55:49 pm »
Fixed the Modified issue (I think):

  • 2e98d119 T(Float)SpinEditEx: set Modified to False if Value is set programmatically.
  • abd3cd5c T(Float)SpinEdit: set Modified to False if Value is set programmatically.

It already worked when you set Text programmatically.

Bart
« Last Edit: October 03, 2021, 12:57:59 pm by Bart »

jamie

  • Hero Member
  • *****
  • Posts: 4919
Re: TSpinEdit possible bug
« Reply #18 on: October 03, 2021, 01:33:05 pm »
No, its not fixed..Sorry.

It's only fixed after the control leaves focus but that is too late.

Implement the OnChange event for the SpinEdit and the Modified must appear as FALSE within that event when changed by code and TRUE when user changes the code, this is the time when things happen to prompt updates or corrections while still there.

 Also the value should remains at its last state when control loses focus of course.


The only true wisdom is knowing you know nothing

Bart

  • Hero Member
  • *****
  • Posts: 4475
    • Bart en Mariska's Webstek
Re: TSpinEdit possible bug
« Reply #19 on: October 03, 2021, 04:07:53 pm »
I see, however, I'm not sure how to solve that.
The problem hrer is that SetValue ultimately calls RealSetText of the Edit (in the case of TSpinEditEx), which then sets Modified to False.

Any idea how to solve that?

Bart

Bart

  • Hero Member
  • *****
  • Posts: 4475
    • Bart en Mariska's Webstek
Re: TSpinEdit possible bug
« Reply #20 on: October 03, 2021, 04:27:04 pm »
I hope I possibly solved it for SpinEditEx in #e868afe1 #16c42cea .

Bart

[ETA] Updated revision hash.
« Last Edit: October 03, 2021, 04:45:10 pm by Bart »

jamie

  • Hero Member
  • *****
  • Posts: 4919
Re: TSpinEdit possible bug
« Reply #21 on: October 03, 2021, 04:33:14 pm »
its all based form the customFloatSpinEdit I think its called, shouldn't it be solved for that so that all others will use the same fix ?
The only true wisdom is knowing you know nothing

Bart

  • Hero Member
  • *****
  • Posts: 4475
    • Bart en Mariska's Webstek
Re: TSpinEdit possible bug
« Reply #22 on: October 03, 2021, 04:49:53 pm »
its all based form the customFloatSpinEdit I think its called, shouldn't it be solved for that so that all others will use the same fix ?

No, the T(Float)SpinEditEx family has access to the underlying Edit control (it does not inherit from TCustomEdit, it is a compound control) , so it has acces to it's OnChange event.
So, you can set Modified there, just before OnChange is called.

T(Float)SpinEdit OTH is a native control and setting I tried setting Modified in TextChanged (which will call Chaged, which calls OnChange), but this does not work, somewhere along the line Modified gets reset to True even if I set it to False in TextChanged.

Bart

hennerd

  • Newbie
  • Posts: 2
Re: TSpinEdit possible bug
« Reply #23 on: October 03, 2021, 07:05:42 pm »
I find that with TSpinEdit, if both MaxValue and MinValue are set to the same number, then the component acts as if no limits were present at all.
This is by design, it is Delphi compatible.
I can see that this is not properly documented though.

Bart

Actually the Cocoa implementation of TSpinEdit behaves differently: if MinValue = 0 and MaxValue = 0, Value cannot be changed, it is always 0.

jamie

  • Hero Member
  • *****
  • Posts: 4919
Re: TSpinEdit possible bug
« Reply #24 on: October 03, 2021, 07:30:58 pm »
its all based form the customFloatSpinEdit I think its called, shouldn't it be solved for that so that all others will use the same fix ?

No, the T(Float)SpinEditEx family has access to the underlying Edit control (it does not inherit from TCustomEdit, it is a compound control) , so it has acces to it's OnChange event.
So, you can set Modified there, just before OnChange is called.

T(Float)SpinEdit OTH is a native control and setting I tried setting Modified in TextChanged (which will call Chaged, which calls OnChange), but this does not work, somewhere along the line Modified gets reset to True even if I set it to False in TextChanged.

Bart
Ok, I've looked at this a little and it seems for the time being the simplest fix would be to add code before the UpdateControl in the SetValue method of TCustomFloatSpinEdit.

This code would take the current OnChange event pointer, store it locally, NIL it, then call the UpdateControl, this will prevent the onchange from triggering.

when UpdateControl returns, restore the OnChange event from the local copy on the stack of SetValue, Set Modified := false, and then Call the Change method which already checks for a valid OnChanged event assigned.

 It seems this Setvalue only gets called when doing the VALUE property assignment.


The only true wisdom is knowing you know nothing

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2712
    • havefunsoft.com
Re: TSpinEdit possible bug
« Reply #25 on: October 03, 2021, 08:07:43 pm »
Actually the Cocoa implementation of TSpinEdit behaves differently: if MinValue = 0 and MaxValue = 0, Value cannot be changed, it is always 0.
this is fixed here (61c40eb..46d12df)
« Last Edit: October 03, 2021, 08:09:28 pm by skalogryz »

jamie

  • Hero Member
  • *****
  • Posts: 4919
Re: TSpinEdit possible bug
« Reply #26 on: October 03, 2021, 08:12:58 pm »
Code: Pascal  [Select][+][-]
  1.   OldOnChange := OnChange; //jp
  2.   OnChange := Nil; //jp
  3.   UpdateControl;  //Original <<<<<<<<<<<<
  4.   OnChange := OldOnChange; //jp;
  5.   Modified := false; //jp;
  6.   If (HandleAllocated)and(Not SameValue(OldValue, Fvalue)) Then Change;  //jp
  7.  

This is what i did, it seems to work for the TSpinEdit modified property..

This is in the SetValue Method of the TcustomFloatSpinEdit....
The only true wisdom is knowing you know nothing

Bart

  • Hero Member
  • *****
  • Posts: 4475
    • Bart en Mariska's Webstek
Re: TSpinEdit possible bug
« Reply #27 on: October 03, 2021, 09:45:40 pm »
I think I may have fixed it in a slightly different way in #2befd9dd.

Please test.

Bart

jamie

  • Hero Member
  • *****
  • Posts: 4919
Re: TSpinEdit possible bug
« Reply #28 on: October 04, 2021, 12:18:20 am »
Yes, it seems to be working now..

I only tested with TSpinEDit, I didn't to the float version but I assume that should also be working..

Good job.
The only true wisdom is knowing you know nothing

Bart

  • Hero Member
  • *****
  • Posts: 4475
    • Bart en Mariska's Webstek
Re: TSpinEdit possible bug
« Reply #29 on: October 04, 2021, 06:43:14 pm »
Yes, it seems to be working now..

I only tested with TSpinEDit, I didn't to the float version but I assume that should also be working..

The changes are in the parent (TFloatSPinEdit), so yes, that should work.
I must admit I did not actually test that, but the theory says it should  O:-)

Bart

 

TinyPortal © 2005-2018