简体   繁体   English

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

[英]Unreasonable error when double-clicking on Object in Design-time in Delphi

Ok, here is the issue: Recently I hit an problem that I was not able to use Accelerator Keys ( aka HotKey s ) on Buttons inside GroupBox. 好的,这是问题所在:最近,我遇到一个问题,即我无法在GroupBox内的按钮上使用加速键(也称为HotKey )。 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 . 一分钟前,我发现了原因,但是现在唯一的问题是,这个原因使我比以前更加困惑,那就是在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. MethodName is VKPInputBtnClick ,实际上被声明为函数,而不是单位中的Method。

What makes me puzzled is that I have not assigned OnClick event handler for VKPInputBtn to any Method at all! 让我感到困惑的是,我根本没有将VKPInputBtn的OnClick事件处理程序分配给任何方法!

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? 重新安装IDE?

Any help much appreciated ... 任何帮助非常感谢...

Double-clicking a control that doesn't have its default event property set causes the IDE to assign that property. 双击未设置默认事件属性的控件,将导致IDE分配该属性。 (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. (这不仅仅是进入代码编辑器的快捷方式;它是F12 。)IDE在源代码中搜索具有所需名称的函数。 If it doesn't find one, then it creates a method in the containing form and assigns it to the component's event property. 如果找不到,则会以包含形式创建一个方法,并将其分配给组件的event属性。 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. 问题显然是IDE在您的案例中发现的东西与它似乎要发生的事件不兼容。 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. 可能是一个错误-它不应该选择非方法-但由于人类选择独立函数的名称与IDE为事件处理程序选择相同名称的频率较低,因此很少遇到。

You have several options: 您有几种选择:

  • Rename VKPInputBtnClick so it doesn't look like it's the OnClick event handler for the VKPInputBtn control. 重命名VKPInputBtnClick以使其看起来像VKPInputBtn控件的OnClick事件处理程序。
  • Make VKPInputBtnClick be a method of the form class. 使VKPInputBtnClick成为表单类的方法。
  • Manually declare a new VKPInputBtnClick method in the form class, and maybe the IDE will select it instead of the standalone function. 在表单类中手动声明一个新的 VKPInputBtnClick方法,IDE可能会选择它而不是独立函数。
  • Type some other name into the OnClick property in the Object Inspector, and then double-click it (or press Enter ). 在Object Inspector的OnClick属性中键入其他名称, 然后双击它(或按Enter )。 The IDE will create a method with that name. IDE将使用该名称创建一个方法。

Try deleting the handler from the .pas file from the declaration and the implementation sections (or copy somewhere if they contain code). 尝试从声明和实现部分的.pas文件中删除处理程序(如果包含代码,则将其复制到某个位置)。 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. 有时,IDE可能会不同步,而唯一可以做的就是将其重置为已知状态。

If that doesnt work see if you can close the form and reopen, or remove the handler from the .dfm file. 如果这样不起作用,请查看是否可以关闭表单并重新打开,或从.dfm文件中删除处理程序。

The components work differently in design and in runtime. 组件在设计和运行时的工作方式不同。 Double clicking on a button in desgintime creates and adds an OnClick handler. 在desgintime中双击按钮会创建并添加一个OnClick处理程序。 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. 您甚至可以在表单的OnCreate中分配它。 If assignment trough the dfm does not succeed. 如果分配通过dfm不会成功。

If this turns out to be a real bug, don't forget to file it with Embarcadero. 如果发现这是一个实际的错误,请不要忘记将其提交给Embarcadero。 You can access the QA app via the tools menu in the IDE or go to the website. 您可以通过IDE中的工具菜单访问质量检查应用程序,或访问网站。

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

Thank you all very much for input. 非常感谢大家的投入。

EDN QC Case: #89543 EDN QC案例:#89543


Notes: 笔记:

This is approach I use to use Accelerator functionality for VKPInputBtnCLick function. 这是我用于VKPInputBtnCLick函数的加速器功能的方法。
- Use Message form this code snipp: Alt key handling algorithm -使用Message编写此代码段: Alt键处理算法
- Change VK_TAB to VK_LMENU ( left ALT ) -将VK_TAB更改为VK_LMENU(左ALT)
- Once ALT message is captured, set global unique value to variable -捕获ALT消息后,将全局唯一值设置为变量
- In FormKeyPress event handler, check if unique global variables value match the one I set before - Execute function. -在FormKeyPress事件处理程序中,检查唯一的全局变量值是否与我之前设置的值匹配-执行函数。

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. 尚未将问题设置为已回答。

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): 正如Toby很久以前说的(但是您显然没有听):

Try deleting the handler from the .pas file ... Then try to recreate the handler for the button. 尝试从.pas文件中删除处理程序。然后尝试重新创建按钮的处理程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Delphi中的设计时拖放? - Design-time drag and drop in Delphi? 如何在使用多线程时使用Delphi设计时FireDac TFDQuery? - How to use Delphi design-time FireDac TFDQuery when using multiple threads? Delphi,在设计时,当使用 nil 所有者创建时,ComponentState、ControlState 的 state 是什么? - Delphi, at design-time, what is the state of ComponentState, ControlState when created with a nil owner? 在设计时在Delphi中检测新组件的插入 - Detecting insertion of new components at design-time in Delphi Delphi:如何为自定义组件创建额外的设计时菜单? - Delphi: How to create an extra design-time menu for a custom component? 如何在设计时更改 Delphi FireDAC tFDMemTable 字段名称 - How to change Delphi FireDAC tFDMemTable field name in design-time 知道是否在运行时或设计时打开了Delphi表单 - Knowing if a Delphi form was opened at run or design-time 创建安装程序时如何从设计时程序包内确保正确的“需要” Delphi运行时程序包定义 - How to ensure correct 'requires' definition of a Delphi run-time package from within a design-time package when creating an installer 双击Delphi XE2应用程序中的TStaticText将标题复制到剪贴板 - double-clicking TStaticText in Delphi XE2 app copies caption to clipboard 在设计时加载图像(图标)时的EOutOfResources - EOutOfResources when loading image (icon) in design-time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM