0

谁能告诉我如何在 OSX firemonkey 应用程序中使 TTrackBar 对象在 C++Builder(或 Delphi)XE7 中只读?我尝试了“锁定”属性,但它似乎不起作用。

干杯

渡渡鸟

4

2 回答 2

1

Enabled属性设置为FalseLocked在设计器中锁定轨迹栏的位置,这样您就不会意外移动它。

于 2014-12-28T06:31:27.037 回答
1

由于您的额外要求,这是另一个答案。没有“只读”属性可以使 TrackBar 保持启用状态。

如果用户尝试更改它,您可以只使用 TrackBar.OnChange 事件并重置该值:

procedure TForm1.TrackBar1Change(Sender: TObject);
begin
  TrackBar1.Value := 50;
end;

更高级的方法是使用观察者来获得真正的只读 TrackBar。

TReadOnlyTrackObserver = class(TInterfacedObject, IEditLinkObserver, IObserver, ISingleCastObserver)
public
  procedure Removed;
  function GetActive: Boolean;
  procedure SetActive(Value: Boolean);
  function GetOnObserverToggle: TObserverToggleEvent;
  procedure SetOnObserverToggle(AEvent: TObserverToggleEvent);

  procedure Update;
  function Edit: Boolean;
  procedure Reset;
  procedure Modified;
  function IsModified: Boolean;
  function IsValidChar(AKey: Char): Boolean;
  function IsRequired: Boolean;
  function GetIsReadOnly: Boolean;
  procedure SetIsReadOnly(Value: Boolean);
  property IsReadOnly: Boolean read GetIsReadOnly write SetIsReadOnly;
  function GetIsEditing: Boolean;
  property IsEditing: Boolean read GetIsEditing;
  procedure BeginUpdate;
  procedure EndUpdate;
  function GetUpdating: Boolean;
  property Updating: Boolean read GetUpdating;
end;

function TReadOnlyTrackObserver.GetActive: Boolean;
begin
  Result := True;
end;

function TReadOnlyTrackObserver.GetIsReadOnly: Boolean;
begin
  Result := True;
end;

// todo: implement the other required functions of TReadOnlyTrackObserver 

var
  MyObserver: IEditLinkObserver;

  MyObserver := TReadOnlyTrackObserver.Create;
  TrackBar1.Observers.AddObserver(TObserverMapping.EditLinkID, MyObserver);
于 2014-12-29T06:11:25.307 回答