Delphi TTrackBar 没有 on complete 事件

Delphi TTrackBar doesn't have on complete event

Delphi TTrackBar 有两个跟踪变化的事件:

  1. OnChange

  2. OnTracking

但是他们两个做同样的事情。例如:

procedure TForm1.TrackBar1Change(Sender: TObject);
begin
  ShowMessage(TrackBar1.Value.ToString);
end;

任何小的更改都会显示 10 消息。

如何检测手机上的最后一次更改?必须在所有跟踪之后发生更改?

这两个事件仅在 Tracking 启用时(默认情况下)做同样的事情。禁用 Tracking 将使 OnChange 仅在用户完成后触发。

这里有一个简短的演示来说明我的意思:

unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
  FMX.Controls.Presentation;

type
  TForm1 = class(TForm)
    TrackBar1: TTrackBar;
    lblChange: TLabel;
    lblTrack: TLabel;
    procedure TrackBar1Change(Sender: TObject);
    procedure TrackBar1Tracking(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    FChangeCount: Integer;
    FTrackCount: Integer;
  public
    procedure DoUpdate;
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.DoUpdate;
begin
  lblChange.Text:= 'Changes:  '+IntToStr(FChangeCount);
  lblTrack.Text:= 'Tracking: '+IntToStr(FTrackCount);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  FChangeCount:= 0;
  FTrackCount:= 0;
  DoUpdate;
end;

procedure TForm1.TrackBar1Change(Sender: TObject);
begin
  Inc(FChangeCount);
  DoUpdate;
end;

procedure TForm1.TrackBar1Tracking(Sender: TObject);
begin
  Inc(FTrackCount);
  DoUpdate;
end;

end.

然后是 FMX 文件:

object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 480
  ClientWidth = 640
  FormFactor.Width = 320
  FormFactor.Height = 480
  FormFactor.Devices = [Desktop]
  OnCreate = FormCreate
  DesignerMasterStyle = 0
  object TrackBar1: TTrackBar
    CanParentFocus = True
    Orientation = Horizontal
    Position.X = 112.000000000000000000
    Position.Y = 96.000000000000000000
    Size.Width = 217.000000000000000000
    Size.Height = 19.000000000000000000
    Size.PlatformDefault = False
    TabOrder = 0
    Tracking = False
    OnChange = TrackBar1Change
    OnTracking = TrackBar1Tracking
  end
  object lblChange: TLabel
    Position.X = 112.000000000000000000
    Position.Y = 152.000000000000000000
    Text = 'lblChange'
  end
  object lblTrack: TLabel
    Position.X = 112.000000000000000000
    Position.Y = 200.000000000000000000
    Text = 'lblTrack'
  end
end