delphiupdown

TUpDown and TEdit with custom captions


I associated a TEdit to a TUpDown. It updates the TEdit text fine automatically with the TUpDown.position value. But I want to display custom captions depending on the TUpDown.position value. For this I unassociated the TEdit from the TUpDown and wrote custom onClick/onChanging handlers. But both of the cases the TUpDown.position contains the previous value (not the incremented/decremented one). What event should I use to update the TEdit.text depending on the right TUpDown.position value?

I use Delphi XE4.


Solution

  • Use the OnChangingEx event. It has a NewValue parameter, that holds the new value to which the control is changing.

    procedure TForm19.UpDown1ChangingEx(Sender: TObject; var AllowChange: Boolean;
      NewValue: Integer; Direction: TUpDownDirection);
    begin
      Edit2.Text := IntToStr(NewValue);
    end;