加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

delphi – 在代码中更改ItemIndex属性时发生ComboBox OnChange事

发布时间:2020-12-15 09:47:52 所属栏目:大数据 来源:网络整理
导读:我在Delphi 10.1 Berlin上使用FMX. 我读了这个(这是我想要的行为): https://stackoverflow.com/a/42933567/1343976 Changing ItemIndex programmatically does not result in the OnChange event being fired. It fires only in response to user interacti
我在Delphi 10.1 Berlin上使用FMX.

我读了这个(这是我想要的行为):

https://stackoverflow.com/a/42933567/1343976

Changing ItemIndex programmatically does not result in the OnChange event being fired. It fires only in response to user interaction.

这只适用于VCL吗?

我要求这个是因为,不幸的是,对于我来说,根据我可以测试的内容,修改代码中的ItemIndex属性会触发OnChange事件.

如果是这样,我怎样才能在FireMonkey中实现与VCL相同的行为?

解决方法

Is this true only for VCL?

在FMX中,许多事情都以不同的方式处理.

If this is true,how can I achieve the same behaviour as VCL in FireMonkey?

一个简单的解决方法是在更改ItemIndex之前以及之后恢复事件之前取消OnChange事件属性.

执行此操作的简单例程就像这样(如@Remy所述):

procedure SetItemIndex(ix : Integer; cb: TComboBox);
var
  original : TNotifyEvent;
begin
  original := cb.OnChange;
  cb.OnChange := nil;
  try
    cb.ItemIndex := ix;
  finally
    cb.OnChange := original;
  end;
end;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读