View Issue Details

IDProjectCategoryView StatusLast Update
0038888LazarusLCLpublic2021-05-18 06:14
Reporterjamie philbrook Assigned ToBart Broersma  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionno change required 
Product Version2.0.13 (SVN) 
Summary0038888: TTrackBar fires an Onchange event via code when it should only be done via USER actions.
DescriptionThis is annoying problem that has been around for a long time now, ever since I ported my first Delphi app over to Lazarus back to like the 1.6.4 days.

Delphi does not call the Onchange event when making changes via code... Only when user moves the slider.

This causes an issue when setting the control from a variable over setting it from a user..

Currently I use a hack to determine if Keyboard or mouse just clicked on the control

These Onchange events for user controls should only change via a user action..

Any one can call the event manually if they wish since its done in code anyways..

Steps To ReproduceDrop a TrackBar on the form and one button, assign a beep or something to the onchange event of the trackbar..

 The button should change the position of the slider, no onchange event should get called but it does.
TagsNo tags attached.
Fixed in Revision
LazTarget-
WidgetsetWin32/Win64
Attached Files

Activities

Martok

2021-05-14 13:10

reporter   ~0130869

I support this request. The need for a "changed by code" flag is really annoying overhead which I usually forget until the first crash during initialization.

Bart Broersma

2021-05-14 14:31

developer   ~0130870

If it's not Delphi compatible, then it should be fixed, regardless wether or not it is annoying ;-)

Bart Broersma

2021-05-14 16:00

developer   ~0130873

Last edited: 2021-05-14 16:00

View 2 revisions

Delphi 7 fires an OnChange when you change Position by code.
So this contradicts the claim of Jamie.

Martok

2021-05-14 18:27

reporter   ~0130877

That's odd. Would have bet money that this used to be different... Might have been the RX control, that had two events.

So a new event is the only sensible solution here too. Either the same as TListBox's OnSelectionChange, or much easier: publish OnEditingDone which is already called only after user changes.

jamie philbrook

2021-05-14 20:46

reporter   ~0130879

I tested this with Delphi 3 and 4, which is all I had at the moment, they do not call the onchange event during code SetPostion..

if Delphi 7 changed this I would of hoped that maybe they also provided a property to indicate the difference, otherwise if you attempt to use this control during onchange event to change its position you get an endless loop. And if you decide to initialize the control to some set value you can't tell the difference between user changes and code changes unless you perform a hack which you shouldn't need to do..

 I'll check Delphi 10 which is on the other PC but I find it hard to believe they would change the behavior like this without some alternate way to tell the difference, if not, then shame on them for doing something that stupid..

jamie philbrook

2021-05-14 20:59

reporter   ~0130881

Last edited: 2021-05-15 01:10

View 2 revisions

This is horrible. I just tested 10 and Delphi devs need to get their act together. The event calls always and there is no way to detect the difference..

 Its strange how advancement seems to be a step backwards for some..

 I've already looked at the code that handles this and its a simple fix but as also, since now Delphi has stepped backwards with the quality of code I guess the LCL users must suffer..

  I will send a note to the DEV team about this btw, I do have an up to date code but in the mean time maybe something could be added like a MODIFIED property for those that knows the difference.

 The MODIFIED property is used in other controls just for this case and maybe it should be added here.

 If you don't want to comply that is find, i'll just recompile the copy I have for my use.. As for Delphi, that isn't going to be so easy unless I create an external variable for it and that is just simply sloppy coding..

Bart Broersma

2021-05-15 20:32

developer   ~0130908

Apparently it is Delphi compatible (wehter we like this or not).
Please close.

B.t.w. Feel free to implement an optional property (boolean or an options set) to disable this. We did similar thing for TPageControl a while ago IIRC.

Dmitry Boyarintsev

2021-05-18 06:14

developer   ~0130936

I can concur Bart's claims. Delphi has been firing OnChange events all the time.

How about this approach instead?

type
  TTrackBarHelper = class helper for TCustomTrackBar
  private
    function GetPositionByCode: Integer;
    procedure SetPositionByCode(AValue: Integer);
  public
    property PositionByCode: Integer read GetPositionByCode write SetPositionByCode;
  end;

{ TTrackBarHelper }

function TTrackBarHelper.GetPositionByCode: Integer;
begin
  Result := Self.Position;
end;

procedure TTrackBarHelper.SetPositionByCode(AValue: Integer);
var
  t : TNotifyEvent;
begin
  t := Self.OnChange;
  if Assigned(t) then begin
    Self.OnChange := nil;
    try
      Self.Position:=AValue;
    finally
      Self.OnChange := t;
    end;
  end
  else
    Self.Position:=AValue;
end;

....
procedure TForm1.Button1Click(Sender: TObject);
begin
  TrackBar1.PositionByCode:=Random(TrackBar1.Max);
end;

Issue History

Date Modified Username Field Change
2021-05-13 21:47 jamie philbrook New Issue
2021-05-14 13:10 Martok Note Added: 0130869
2021-05-14 14:31 Bart Broersma Note Added: 0130870
2021-05-14 16:00 Bart Broersma Note Added: 0130873
2021-05-14 16:00 Bart Broersma Note Edited: 0130873 View Revisions
2021-05-14 16:00 Bart Broersma Status new => feedback
2021-05-14 16:00 Bart Broersma LazTarget => -
2021-05-14 18:27 Martok Note Added: 0130877
2021-05-14 20:46 jamie philbrook Note Added: 0130879
2021-05-14 20:46 jamie philbrook Status feedback => new
2021-05-14 20:59 jamie philbrook Note Added: 0130881
2021-05-15 01:10 jamie philbrook Note Edited: 0130881 View Revisions
2021-05-15 20:32 Bart Broersma Assigned To => Bart Broersma
2021-05-15 20:32 Bart Broersma Status new => resolved
2021-05-15 20:32 Bart Broersma Resolution open => no change required
2021-05-15 20:32 Bart Broersma Widgetset Win32/Win64 => Win32/Win64
2021-05-15 20:32 Bart Broersma Note Added: 0130908
2021-05-18 06:14 Dmitry Boyarintsev Note Added: 0130936