Problem with handling WM_COMMAND
Original Reporter info from Mantis: michal_niklas
-
Reporter name: Michał Niklas
Original Reporter info from Mantis: michal_niklas
- Reporter name: Michał Niklas
Description:
I have form with MainMenu and I want to intercept when the user selects a command item from a menu. This works in Delphi:
type
TForm1 = class(TForm)
... // Memo and MainMenu created
protected
procedure WMCommand(var Info: TWMCommand); message WM_COMMAND;
end;
procedure TForm1.WMCommand(var Info: TWMCommand);
begin
if (Info.ItemID < 10) then
Memo1.Lines.Add('WMCommand ' + IntToStr(Info.ItemID));
end;
In MainMenu I added some items and when I select those items from menu then my Memo1 is filled with:
WMCommand 2
WMCommand 3
WMCommand 3
WMCommand 2
WMCommand 5
...
I ported this application to FPC/Lazarus, but it seems that WM_COMMAND handler is not called! When I set breakpoint in TForm1.WMCommand in Delphi then Delphi stopped many times before main form appeared. Lazarus never stopped on this breakpoint. I think something is broken with WM_COMMAND in Lazarus, but maybe I don't know something. Any idea?
I use Lazarus 0.9.28.2 beta with FPC 2.2.4 on WinXP.
EDIT:
Using Winspector I checked that MainMenu generates WM_COMMAND:
WM_COMMAND
Code: 0
Control ID: 2
Control HWND: 0x00000000
Message Posted
Time: 09:37:14.0968
I think there is bug in Lazarus/FPC in WM_COMMAND message method handling.
Steps to reproduce:
- create simple form with MainMenu (some items) and TEdit.
- in form add WM_COMMAND message method:
procedure WMCommand(var Info: TWMCommand); message WM_COMMAND;
in its implementation add something to TEdit:
if (Info.ItemID < 10) then
Memo1.Lines.Add('WMCommand ' + IntToStr(Info.ItemID));
- run application
- in Winspector you will see that WM_COMMAND is posted by MainMenu, but its message method is never fired
I uploaded source file.
Mantis conversion info:
- Mantis ID: 15521
- OS: WinXP
- OS Build: SP3
- Platform: Win32
- Version: 2.2.4