FMXTCustomButtonRepeatClick (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example shows how to use the styles and TCustomButton.RepeatClick property to enable a click-and-hold behavior of TSpinBox increment and decrement arrows.

To build and test this example:

The styles are used to identify the arrow buttons of the TSpinBox. To view the styles applied over TSpinBox, go to Style Designer by right-clicking the TSpinBox, and choose Edit Default Style....

SpinBoxStyle.png

Code

The method that enables click-and-hold behavior:

procedure TForm1.SetRepeatClick(ASpinBox:TSpinBox; const AValue:Boolean);

  procedure SetButton(const AName:String);
  var B : TFmxObject;
  begin
    //Finds the arrow buttons of the SpinBox1.
    B := ASpinBox.FindStyleResource(AName);
    if Assigned(B) and (B is TCustomButton) then
    //Enables the repetition of the click action.  
       TCustomButton(B).RepeatClick:=AValue;
  end;

begin
  //Enables the repetition for the decrement arrow.
  SetButton('minusbutton');
  //Enables the repetition for the increment arrow.
  SetButton('plusbutton');
end;

Call the SetRepeatClick method within the event handler of the OnClick event of the added button.

procedure TForm1.Button1Click(Sender: TObject);
begin
   SetRepeatClick(SpinBox1,true);
end;

The SetRepeatClick method must be called after the styles are applied over the form and its components. This method has no effect if called on the TCustomForm.OnCreate event handler of the form.

Uses

See Also