如何将 ItemIndex 添加到 TRibbonComboBox?
我刚刚发现 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;
I just discovered that the Delphi TRibbonComboBox doesn't have an item index, and it should.
I'd like to fix this locally at least for the unit, and I think Delphi 2009 added a way to introduce new methods to an outside class without having to descent from the class, but I can't remember how.
Is there a way to add 'function ItemIndex: integer;' to the TRibbonComboBox class at least within the local unit with out having to mess with the original component? (Or am I thinking C#?)
Thanks!
Here's the answer/implementation, thx 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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用类帮助器,如下所示:
需要注意的是,您不能以这种方式添加任何新字段,因此您必须能够根据 TRibbonComboBox 公开提供的信息计算此函数的返回值。
You can use a class helper, like this:
The caveat is that you can't add any new fields this way, so you have to be able to calculate the return value of this function from information publicly available from TRibbonComboBox.