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

delphi – 在代码中更改ItemIndex属性时发生ComboBox OnChange事件,第1张

概述我在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 respon 我在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;
总结

以上是内存溢出为你收集整理的delphi – 在代码中更改ItemIndex属性时发生ComboBox OnChange事件全部内容,希望文章能够帮你解决delphi – 在代码中更改ItemIndex属性时发生ComboBox OnChange事件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1272479.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存