English 中文(简体)
Problem with WM_COMMAND on Lazarus/FPC
原标题:

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 and I reported it: http://bugs.freepascal.org/view.php?id=15521

最佳回答

In a LCL application you have the following layers:

  • Application
  • LCL
  • Widget set Interface (e.g. win32/win64, qt, gtk2, carbon)
  • Widget set

WM_COMMAND is a winapi message from the widgetset Layer to the Widget Set interface layer. These messages are not passed to the higher layers, having portability in mind, other widget sets don t produce such messages.

If you want to capture the message, then you must write non-portable widgetset specific code (winapi code in this case). You can override the windowproc with setwindowlong. See the Lazarus wiki for an example.

问题回答

暂无回答




相关问题
determining the character set to use

my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...

Help with strange Delphi 5 IDE problems

Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How convert string to integer in Oxygene

In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签