Question

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 ...

Was it helpful?

Solution

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.

OTHER TIPS

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.

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.

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.

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top