Equivalent for 'OnDropDown' in Combobox on FMX

In VCL I use OnDropDown to populate the combobox before it is dropped down with any potential changes to the list.

In FMX this on unit does not exist and all the alternatives I’ve tried do not work ‘properly’.

Anyone solved this?

Define “properly”. The OnPopup event works OK for me.

Edit: Just realised what you were asking, i.e. changing the items when “dropdown” occurs. There might be some other way - just not via OnPopup

I believe in FMX there is an OnPopUp event you can use the same way

Here’s one way, using an “interposer” declaration:

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.ListBox;

type
  TComboBox = class(FMX.ListBox.TComboBox)
  private
    FOnDropDown: TNotifyEvent;
  protected
    procedure DropDown; override;
    property OnDropDown: TNotifyEvent read FOnDropDown write FOnDropDown;
  end;

  TForm1 = class(TForm)
    ComboBox1: TComboBox;
  private
    procedure ComboBox1DropDownHandler(Sender: TObject);
  public
    constructor Create(AOwner: TComponent); override;
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

{ TComboBox }

procedure TComboBox.DropDown;
begin
  if not DroppedDown and Assigned(FOnDropDown) then
    FOnDropDown(Self);
  inherited;
end;

constructor TForm1.Create(AOwner: TComponent);
begin
  inherited;
  ComboBox1.OnDropDown := ComboBox1DropDownHandler;
end;

procedure TForm1.ComboBox1DropDownHandler(Sender: TObject);
begin
  // Do your changes to ComboBox1.Items here
end;

end.
1 Like

No, that seems to fire after the dropdown list is displayed.

That works great, Thanks!

1 Like