We have an application that can be run in Simple or Advanced mode. The difference is what main menu entries are visible. The problem is that RAD Studio XE2 silently deletes the OnClick property value set in the dfm. It points to a procedure hiding some menu items in the Main Menu > File menu.
Steps:
1. A fresh checkout from subversion to a new folder on disk, one that never existed before.
2. Opening the main form’s dfm and pas files in notepad++ to ensure that the “OnClick = MenuItem_File1Click” row is there and that procedure MenuItem_File1Click is in interface and implementation of pas file. Yes, everything looks good.
3. Open project in RAD Studio XE2.
4. OnClick property of File menu item in Object Inspector is blank.
We have some other menu items that were handled in FormShow and they work as expected, hidden in Simple mode and visible in Advanced. The workaround was to move the functionality inside the MenuItem_File1Click to FormShow. But I really want to understand why it happened in the first place.
Can anyone explain this behaviour? Has anyone else come across something like this? I tried renaming the procedure to something definitiely not system-like but the IDE removed it anyway.
If you hook up your
Menu(or aButton) with anAction, then theActionis supposed to take over the control of all these properties:AutoCheck, Caption, Checked, Enabled, HelpContext, Hint, GroupIndex, Bitmap/ImageIndex, ShortCut, Visibleand in your caseOnClick/Execute.That’s the “raison d’etre” of the Actions in the 1st place.
So if you leave your
Actionwithout anExecuteevent handler, you are de facto puttingnilinto your Control’sOnClickevent.And this happens whenever the controls are read from the dfm at the moment the Action specified in the dfm is hooked to the control. Just try to set the OnClick, then switch to View As Text and back (Alt+F12 twice) and your OnClick is gone…
See the VCL source:
Update: … but this should not happen if you have code in the OnClick event.
This looks like a bug. When the MenuItem is read from the dfm, the parent Form is not yet fully loaded and the OnClick appears as
but
Assigned(FOnClick)returnsFalse!!!!So
if not CheckDefaults or (@Self.OnClick=nil) thenwould be a better test