Delphi设计时双击对象时出现不合理的错误

发布于 2024-10-01 20:39:40 字数 484 浏览 7 评论 0原文

好的,问题是这样的: 最近我遇到了一个问题,我无法在按钮上使用加速键(又名 HotKey)在组框内。就在一分钟前我找到了原因,但现在唯一的问题是这个原因让我比以前更加困惑,那就是在Form上找不到这样的带有加速器的按钮。效果是,当我在设计时双击受影响的按钮时,我收到错误“属性和方法不兼容”。

MethodName 是 VKPInputBtnClick,它实际上被声明为函数,而不是 Unit 中的 Method。

让我感到困惑的是,我根本没有将 VKPInputBtn 的 OnClick 事件处理程序分配给任何方法!

我怎么可能可以编译程序并且没有运行时问题...但是在设计时双击按钮有如此烦人的问题....

有什么解决方案吗?重新安装IDE?

任何帮助非常感谢...

Ok, here is the issue:
Recently I hit an problem that I was not able to use Accelerator Keys ( a.k.a HotKeys ) on Buttons inside GroupBox. Just a minute ago I found out why, but now only problem is that this reason makes me even more puzzled than before, which is that Such button with accelerator cannot be found on Form. Effect is that when I double click to affected buttons with double-click while in Design-time, I get error "Property and method are not compatible".

MethodName is VKPInputBtnClick, that is actually declared as function, not as Method in Unit.

What makes me puzzled is that I have not assigned OnClick event handler for VKPInputBtn to any Method at all!

How it is possible that I can compile program and have no run-time problems ... but in Design-time double click on button has such annoying issues ....

Any solution? Reinstall of IDE?

Any help much appreciated ...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

在你怀里撒娇 2024-10-08 20:39:40

双击未设置默认事件属性的控件会导致 IDE 分配该属性。 (它不仅仅是进入代码编辑器的快捷方式;它是 F12。)IDE 在源代码中搜索具有所需名称的函数。如果没有找到,那么它会在包含的表单中创建一个方法并将其分配给组件的事件属性。但是,如果它确实找到了具有正确名称的内容,它会尝试分配它而不创建任何新内容。

显然,问题在于 IDE 在您的案例中找到的内容与它似乎伴随的事件不兼容。可能是一个错误(它不应该选择非方法),但这是一个很少遇到的错误,因为人们为独立函数选择与 IDE 为事件处理程序选择相同名称的频率较低。

您有多种选择:

  • 重命名 VKPInputBtnClick,使其看起来不像是 VKPInputBtn 控件的 OnClick 事件处理程序。
  • 使VKPInputBtnClick成为表单类的方法。
  • 在表单类中手动声明一个 VKPInputBtnClick 方法,也许 IDE 会选择它而不是独立函数。
  • 在对象检查器的 OnClick 属性中键入一些其他名称,然后双击它(或按 Enter)。 IDE 将创建一个具有该名称的方法。

Double-clicking a control that doesn't have its default event property set causes the IDE to assign that property. (It's not just a shortcut for going to the code editor; that's F12.) The IDE searches the source code for a function with the desired name. If it doesn't find one, then it creates a method in the containing form and assigns it to the component's event property. But if it does find something with the right name, it attempts to assign it without creating anything new.

The problem, apparently, is that the thing the IDE finds in your case isn't compatible with the event it appears to go with. Probably a bug — it shouldn't select non-methods — but a rarely encountered one given the low frequency with which humans choose the same name for standalone functions as the IDE chooses for event handlers.

You have several options:

  • Rename VKPInputBtnClick so it doesn't look like it's the OnClick event handler for the VKPInputBtn control.
  • Make VKPInputBtnClick be a method of the form class.
  • Manually declare a new VKPInputBtnClick method in the form class, and maybe the IDE will select it instead of the standalone function.
  • Type some other name into the OnClick property in the Object Inspector, and then double-click it (or press Enter). The IDE will create a method with that name.
木有鱼丸 2024-10-08 20:39:40

尝试从 .pas 文件的声明和实现部分删除处理程序(如果它们包含代码,则复制到某个位置)。然后尝试重新创建按钮的处理程序。有时 IDE 可能会不同步,所能做的就是重置回已知状态。

如果这不起作用,请查看是否可以关闭表单并重新打开,或者从 .dfm 文件中删除处理程序。

Try deleting the handler from the .pas file from the declaration and the implementation sections (or copy somewhere if they contain code). Then try to recreate the handler for the button. Sometimes the IDE can get out of sync and all that can be done is to reset back to a known state.

If that doesnt work see if you can close the form and reopen, or remove the handler from the .dfm file.

甜尕妞 2024-10-08 20:39:40

这些组件在设计和运行时的工作方式不同。双击 desgintime 中的按钮会创建并添加 OnClick 处理程序。这解释了为什么行为不同。

希望我正确理解你的问题。您的表单上有一个组件,但您无法分配正确的事件处理程序,因为自动创建的事件处理程序与预期的事件处理程序的类型不同?

在这种情况下,创建您自己的事件处理程序并分配它。您甚至可以在表单的 OnCreate 中分配它。如果通过 dfm 分配不成功。

The components work differently in design and in runtime. Double clicking on a button in desgintime creates and adds an OnClick handler. That explains why the behavior is different.

Hopefully I understand your question correctly. You have a component on your form, and you are not able to assign a correct eventhandler because the automatically created eventhandler is a different type than the expected eventhandler?

In that case, create your own eventhandler and assign it. You can even assign it in the OnCreate of the form. If assignment trough the dfm does not succeed.

遇见了你 2024-10-08 20:39:40

如果这确实是一个错误,请不要忘记向 Embarcadero 提交。您可以通过 IDE 中的工具菜单访问 QA 应用程序或访问网站。

If this turns out to be a real bug, don't forget to file it with Embarcadero. You can access the QA app via the tools menu in the IDE or go to the website.

飘逸的'云 2024-10-08 20:39:40

无论如何,问题已得到解答,很明显,此错误消息应该是 RAD Studio XE 错误,因为 IDE 以错误的方式比较对象的实际属性和所需属性。

非常感谢大家的意见。

EDN QC 案例:#89543


注释:

这是我使用 VKPInputBtnCLick 函数的加速器功能的方法。
- 使用此代码片段中的消息:Alt 键处理算法
- 将VK_TAB更改为VK_LMENU(左ALT)
- 捕获 ALT 消息后,将全局唯一值设置为变量
- 在 FormKeyPress 事件处理程序中,检查唯一的全局变量值是否与我之前设置的值匹配
- 执行函数。

希望它对愿意这样做的其他人有所帮助。此外,也欢迎使用一些更时尚、更简洁的方式来实现此功能。

尚未将问题设置为已回答。

Anyway, Question is answered and it is clear that this error message should be a RAD Studio XE bug because IDE in wrong way compares actual and needed properties for Object.

Thank you all very much for input.

EDN QC Case: #89543


Notes:

This is approach I use to use Accelerator functionality for VKPInputBtnCLick function.
- Use Message form this code snipp: Alt key handling algorithm
- Change VK_TAB to VK_LMENU ( left ALT )
- Once ALT message is captured, set global unique value to variable
- In FormKeyPress event handler, check if unique global variables value match the one I set before
- Execute function.

Hope it helps to others willing to do this. Also, some more sleek and clean way to achieve this functionality are welcome, too.

Not setting Question as Answered yet.

日裸衫吸 2024-10-08 20:39:40

实际上被声明为函数,而不是 Unit 中的 Method。

方法处理程序必须是过程,而不是函数。因此它不起作用。

正如托比很久以前说过的(但你显然没有听):

尝试从 .pas 文件中删除处理程序...
然后尝试重新创建按钮的处理程序。

is actually declared as function, not as Method in Unit.

Method handlers must be procedures, not functions. Hence it doesn't work.

As Toby said a long time ago (but you obviously didn't listen):

Try deleting the handler from the .pas file ...
Then try to recreate the handler for the button.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文