Recent

Author Topic: A concept idea for a change of the TTrackBar to better control the OnChange.  (Read 920 times)

jamie

  • Hero Member
  • *****
  • Posts: 4848
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..

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, Lmessages,
  9.   StdCtrls;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14. TTrackBar = Class(ComCtrls.TtrackBar)
  15.   Private
  16.   Procedure HasChanged(var msg:TLMessage) Message LM_CHANGED;
  17.   Procedure HasActived(Var msg:TLMessage) Message LM_Activate;
  18.   Public
  19.   Modified :Boolean;
  20. end;
  21.  
  22.   TForm1 = class(TForm)
  23.     Button1: TButton;
  24.     TrackBar1: TTrackBar;
  25.     procedure Button1Click(Sender: TObject);
  26.     procedure TrackBar1Change(Sender: TObject);
  27.   private
  28.  
  29.   public
  30.   end;
  31.  
  32. var
  33.   Form1: TForm1;
  34.  
  35. implementation
  36.  
  37. {$R *.lfm}
  38.  
  39. { TForm1 }
  40.  
  41. procedure TForm1.Button1Click(Sender: TObject);
  42. begin
  43.   TrackBar1.Position := Round(TrackBar1.Max * Random);
  44. end;
  45.  
  46. procedure TForm1.TrackBar1Change(Sender: TObject);
  47. begin
  48.   caption := TrackBar1.Modified.Tostring;
  49.   TrackBar1.Modified := false;
  50. end;
  51.  
  52. Procedure TTrackBar.HasChanged(Var msg:TLMessage);
  53. Begin
  54.   Modified := True;
  55.   Inherited;
  56. end;
  57. procedure TTrackBar.HasActived(var Msg:TLmessage);
  58. begin
  59.   Beep;
  60.   Modified := false;
  61.   Inherited;
  62. end;
  63.  
  64. end.
  65.  
  66.  
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 4848
Example Demo attached and a correction made for the focus part..

Would like to know If this works on other targets other than windows ?
The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018