选项卡上缺少UI控件,为什么调用HandleNeeded可以解决该问题? [英] Missing UI Control on tab, why calling HandleNeeded fixes it?

查看:45
本文介绍了选项卡上缺少UI控件,为什么调用HandleNeeded可以解决该问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UI对象附加到一个选项卡,该选项卡仅在与程序进行一定顺序的交互时才会丢失,如果丢失,关闭程序将导致AV和无效窗口句柄的错误.当我试图找出原因时,我发现在开始时调用其.Handle或.HandleNeeded可以解决此问题.但这并不能回答为什么它可以解决问题.

I had one UI object attached to a tab that will go missing only under a certain sequence of interaction with the program, and if it's missing, closing the program will result in AV and error of Invalid Window Handle. As I was trying to find out why, I found that calling its .Handle or .HandleNeeded at the start will fix the problem. But that doesn't answer why does it fix the problem.

所以我希望知道这是普遍现象吗?有人遇到过这个奇怪的错误吗?知道原因吗?

So I would hope to know that is this common? Has anyone encountered this strange bug before? And know the reason?

推荐答案

如果使用的是TabControl,则Delphi仅在需要页面时才为每个页面创建控件(出于速度和资源使用的原因).尝试访问未显示的页面上的控件将导致问题,除非您调用.HandleNeeded.调用.HandleNeeded告诉Delphi您现在需要手柄,并消除了问题.

If you're using a TabControl, Delphi only creates the controls for each page when the page is needed (for speed and resource usage reasons). Trying to access controls on a page that hasn't been shown will cause issues, unless you call .HandleNeeded. The call to .HandleNeeded tells Delphi you need the handle now, and eliminates the problem.

这不是错误,顺便说一句.如上所述,这是一个有意的设计决策,目的是提高速度并最大程度地减少资源使用.

It's not a bug, BTW. It's an intentional design decision, for speed and minimization of resource usage as I mentioned above.

这篇关于选项卡上缺少UI控件,为什么调用HandleNeeded可以解决该问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆