How to add ItemIndex to TRibbonComboBox?

I just discovered that the Delphi TRibbonComboBox doesn't have an item index and it should.

I would like to fix this locally, at least for the device, and I think Delphi 2009 added a way to introduce new methods to the outer class without having to descend from the class, but I can't remember how to do that.

Is there a way to add 'function ItemIndex: integer;' to the TRibbonComboBox class, at least in the local block, without linking to the original component? (Or C #, I think?)

Thank!

Here's an answer / implementation, thanks Mason!

TRibbonComboBoxHelper = class helper for TRibbonComboBox
public
  function GetItemIndex: integer;
  procedure SetItemIndex(Index : integer);
  property ItemIndex : integer read GetItemIndex write SetItemIndex;
end;

function TRibbonComboBoxHelper.GetItemIndex: integer;
begin
  result := Items.IndexOf(Text);
end;

procedure TRibbonComboBoxHelper.SetItemIndex(Index: integer);
begin
  if (Index >= 0) and (Index < Items.Count) then
    Text := Items[Index];
end;

      

+2


source to share


1 answer


You can use a helper class like:

type
  TRibbonComboBoxHelper = class helper for TRibbonComboBox
  public
    function ItemIndex: integer;
  end;

      



The caveat is that you cannot add new fields this way, so you should be able to compute the return value of this function from the public information from the TRibbonComboBox.

+2


source







All Articles