Consider this , I use this type of code in Lazarus when dealing with the trackbar in cases where we need to determine the difference between User changes and code changes..
So I elected to use what is already established name "MODIFIED" and a few other controls..
Please examine this idea..
The idea is to clear the MODIFID property when the control receives focus and it gets set when user is using the mouse or keys to change the value, otherwise code changes (position) does not set this value..
Also, this value will remain set to what it was the last time when the control loses focus, this is to aid in determining if the control was user changed in case you want to check the state of the control later on in code.
This is how it's currently done in Tmemo, TEDIT and a couple of others I can't think of at the moment, the value will remain what it was set to when the control loses input but will be cleared when it receives focus..
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, Lmessages,
StdCtrls;
type
{ TForm1 }
TTrackBar = Class(ComCtrls.TtrackBar)
Private
Procedure HasChanged(var msg:TLMessage) Message LM_CHANGED;
Procedure HasActived(Var msg:TLMessage) Message LM_Activate;
Public
Modified :Boolean;
end;
TForm1 = class(TForm)
Button1: TButton;
TrackBar1: TTrackBar;
procedure Button1Click(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
TrackBar1.Position := Round(TrackBar1.Max * Random);
end;
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
caption := TrackBar1.Modified.Tostring;
TrackBar1.Modified := false;
end;
Procedure TTrackBar.HasChanged(Var msg:TLMessage);
Begin
Modified := True;
Inherited;
end;
procedure TTrackBar.HasActived(var Msg:TLmessage);
begin
Beep;
Modified := false;
Inherited;
end;
end.