Recent

Author Topic: SpinEdit | Active User Change event?  (Read 1056 times)

mrmaxmusterman

  • New Member
  • *
  • Posts: 16
SpinEdit | Active User Change event?
« on: September 10, 2021, 09:11:34 pm »
I have a SpinEdit implemented into my program.

I also have an if statement decreasing the value of the spinEdit if the value of it is greater than the length of an input (type string).

What i now want to implement is an alert to the User (ShowMessage) if the user reached the max value by himself.

In the event that the user deletes parts of the string, i dont want any alerts to occur, just when the user is increasing the spinedit value by him/herself and his the border through my if statement.

Is there any way that this could be done?

My if statement:

Code: Pascal  [Select][+][-]
  1. if Count_SpinEdit.Value>length(Input_Edit.Text) then
  2.   begin
  3.    Count_SpinEdit.Value:=length(Input_Edit.Text);
  4.   end;
  5.  

Bart

  • Hero Member
  • *****
  • Posts: 4472
    • Bart en Mariska's Webstek
Re: SpinEdit | Active User Change event?
« Reply #1 on: September 10, 2021, 10:49:35 pm »
It is totally unlcear to me what you want to achieve.

Bart

mrmaxmusterman

  • New Member
  • *
  • Posts: 16
Re: SpinEdit | Active User Change event?
« Reply #2 on: September 10, 2021, 10:55:10 pm »
Ok. Let me ask me question in a more direct way then. Is there an event that could be triggered through the user increasing the value of the spinedit through the buttons (increase / decrease) or even through typing in a number?

Bart

  • Hero Member
  • *****
  • Posts: 4472
    • Bart en Mariska's Webstek
Re: SpinEdit | Active User Change event?
« Reply #3 on: September 10, 2021, 10:56:18 pm »
OnChange?

Bart

mrmaxmusterman

  • New Member
  • *
  • Posts: 16
Re: SpinEdit | Active User Change event?
« Reply #4 on: September 10, 2021, 10:59:54 pm »
Isn’t it technically possible that the onchange event could be triggered through a change in another procedure? E.g. by changing the value of it to the length of an input as in my example?

Bart

  • Hero Member
  • *****
  • Posts: 4472
    • Bart en Mariska's Webstek
Re: SpinEdit | Active User Change event?
« Reply #5 on: September 10, 2021, 11:07:35 pm »
Yes, but since you yourself set this value in your program you can e.g. disable the OnChange before setting the value, or set a flag indicating you programatically changed the value and inspect this in OnChange.
The first option seems a bit more fool proof to me:

Code: Pascal  [Select][+][-]
  1. ...
  2.   SpinEdit1.OnChange := nil;
  3.   SpinEdit1.Value := 123;
  4.   SpinEdit1.OnChange := @SpinEdit1Change; //the value it had before, hardcoded in this case
  5.   ...

Bart
« Last Edit: September 11, 2021, 11:24:14 am by Bart »

Bart

  • Hero Member
  • *****
  • Posts: 4472
    • Bart en Mariska's Webstek
Re: SpinEdit | Active User Change event?
« Reply #6 on: September 11, 2021, 11:29:13 am »
Or, without having to hardcode the name of the OnChange event:
Code: Pascal  [Select][+][-]
  1. var
  2.   SavedOnChange: TNotifyEvent;
  3. begin
  4.   SavedOnChange := SpinEdit1.OnChange;
  5.   SpinEdit1.OnChange := nil;
  6.   SpinEdit1.Value := SpinEdit1.Value + 1;
  7.   SpinEdit1.OnChange := SavedOnChange;
  8. end;

Bart

jamie

  • Hero Member
  • *****
  • Posts: 4915
Re: SpinEdit | Active User Change event?
« Reply #7 on: September 11, 2021, 12:20:07 pm »
Isn’t it technically possible that the onchange event could be triggered through a change in another procedure? E.g. by changing the value of it to the length of an input as in my example?

There is a MODIFIED property within the spin edit control which most likely is from the TEDIT control at some point however, the use of it does not follow the path of how it is suppose to work, at least in my old version of laz.

 Modified is suppose to report to user code when events like OnChanges take place if the user using keyboard or mouse input made the change and not by code.

 I see that it changes regardless either way, it should only be set to true if user made the changes and remain to its current value otherwise.

Tmemo and Tedit does not or should not be setting this MODIFIED property when values are not changed by user, the TSpinEdit should follow the same path..


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

wp

  • Hero Member
  • *****
  • Posts: 8891
Re: SpinEdit | Active User Change event?
« Reply #8 on: September 11, 2021, 04:04:32 pm »
When Delphi sets the Modified property is as inconsistent as firing the OnChange event. And since Lazarus must be Delphi-compatible it inherits this annoyance.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

 

TinyPortal © 2005-2018