delphi - 如何将 ItemIndex 添加到 TRibbonComboBox?

标签 delphi delphi-2009 delphi-2010 ribbon

我刚刚发现 Delphi TRibbonComboBox 没有项目索引,它应该。

我想至少为该单元在本地解决这个问题,我认为 Delphi 2009 添加了一种向外部类引入新方法而不必从类中下降的方法,但我不记得如何。

有没有办法添加'function ItemIndex:integer;'至少在本地单元内到 TRibbonComboBox 类,而不必弄乱原始组件? (或者我在想 C# 吗?)

谢谢!

这是答案/实现,谢谢梅森!

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;

最佳答案

您可以使用类助手,如下所示:

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

需要注意的是,您不能以这种方式添加任何新字段,因此您必须能够从 TRibbonComboBox 公开的信息中计算此函数的返回值。

关于delphi - 如何将 ItemIndex 添加到 TRibbonComboBox?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1390485/

相关文章:

delphi - 相当于Delphi 2010 dbExpress 中的TUpdateSQL?

delphi - Delphi 2009 中的函数 CreateProcess 中的访问冲突

multithreading - TMonitor 同步/Application.ProcessMessages

delphi - 一个简单的delphi表单应用程序是否需要任何库或依赖项来部署?

delphi - Windows 7 上的 WIA 2 -- Delphi

delphi - 是否有一些已知的单元在使用 COM 库时自动初始化它?

multithreading - delphi中的线程安全

delphi - TXMLDocument.Active := False causes FastMM4 errormessage "FastMM detected that a block has been modified after being freed"

delphi - delphi中使用RTTI递归迭代内部记录

delphi - Delphi 或 C++Builder 应用程序的默认工作目录是什么