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 beta with FPC 2.2.4 on WinXP.


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:

-------------Problems Reply------------

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.

Category:delphi Views:1 Time:2010-01-12

Related post

  • What are good Lazarus/FPC Resources? 2011-09-18

    I want to learn to develop applications in Lazarus, but I need resources, preferably books, to Lazarus. Keep in mind that I know 0 of Pascal. Thanks. --------------Solutions------------- Lazarus - The Complete Guide can be found here. UPDATE: http://

  • What are the differences between implementation of Interfaces in Delphi and Lazarus (FPC)? 2012-03-06

    We have a project full of custom components that today is working in Lazarus and Delphi. I'm thinking in code interfaces on it, but I am not much familiar with them. What I would like to know is: What are the implementation nuances from Delphi and La

  • GetUserName under MacOSX with Lazarus FPC 2011-12-21

    i'm right now porting an application which was made for Window using Lazarus to MacOSX. I've a few WinAPI calls which i need to recode to make it work under Mac. Now i need to find out the user name of the current mac account which is logged in the O

  • Interfaces in Lazarus/FPC: Multiple inheritance 2012-04-02

    I'm trying to create a shell extension to provide EXIF information for JPEG files in Windows Explorer "infotips", and am using Lazarus as this needs to produce an x64 DLL. Does Lazarus support multiple inheritance with interfaces, and if so, how do I

  • Problem with converting Delphi form to Lazarus 2009-11-16

    After I ported Delphi Windows service app to FPC Linux console app I tried to port program with GUI. I installed newest Lazarus on my Windows machine and converted simple "hello world" app. One unit has form (.dfm file in Delphi). This form was conve

  • Handheld Development, Lazarus or Turbo Delphi.Net 2009-07-01

    I begin to program some handheld program as hobby, right now i currently have knowledge on Blackberry App (Java), Symbian S60 (PyS60) and J2ME Something that i wanna learn was Windows Mobile/Pocket PC and iPhone development, but since i don't use Mac

  • Delphi & Lazarus both installed 2010-08-02

    Just a quick question for those of you that know. Is it possible to have both Delphi (ver 7) and Lazarus installed at the same time. I want to make sure the Lazarus install will not interfere with my current Delphi install in ANY WAY. I would have as

  • Execute code in the context of the main thread (Lazarus) 2010-08-26

    I have to execute some code in the context of the main thread. I am using Lazarus + FPC. I receive an event from a thread inside a DLL (shared library if on linux) and my callback function gets called. Note that this function is not a member of any c

  • How to use functions defined in a C++-produced .dll or .lib file within Lazarus (freepascal)? 2011-08-11

    I want to use functions from the 'ANN' library (Approximate Nearest Neighbor) in my Lazarus code. This application is written in C++, and comes with source code. How can I access the functions from within Lazarus/FreePascal? Edit: Lazarus/FPC is simi

  • Detecting installed lazarus IDE 2011-03-21

    which is the proper way to detect if the lazarus IDE is installed in a system programatically using delphi? for example to detect if delphi 7 is installed i can check this key HKLM\Software\Borland\Delphi\7.0. I search for a similar key for lazarus i

  • Pascal and its current applications 2009-06-08

    I studied Turbo Pascal in 1997 and I liked it very much as a language. Everything was very structured and the compiler made sure you did things the right way. I later tried Delphi but never got very interested in it. Since then I've used a lot of dif

  • Delphi programs blocked by Kaspersky Antivirus. Need workarround 2010-09-17

    I have a piece of code that is trying to write to disk many files in one second. However, it fails wince I have installed Kaspersky Anrivirus 2011. Stream:= TFileStream.Create(sName, fmCreate); The code totally worked with Kaspersky 2010 and also wor

  • Building cross-platform Delphi applications 2011-01-13

    I downloaded Lazarus, but have worked with Embarcadero Delphi IDE too. I have a question about building cross-platform Delphi applications. How can I build them under win32 environment? I read the wiki from Lazarus site, that explains how to do it, b

  • Why does my Firemonkey app open a terminal window on OSX but not on Win32? 2011-09-09

    I created a simple testbed app in Delphi XE2, and compiled both a Win32 and OSX version of the application. I zipped up the OSX version, along with a copy of the libcgunwind dylib runtime file and copied this files to a Mac i have access to. When I u

  • Delphi Free and Open Source Components that are still maintained 2008-09-26

    It would be good to compile a new inventory here of Delphi FOSS components that are very useful, also with rare and difficult to find functionality and still maintained for the latest Delphi versions. Examples of rare components are for instance "TWA

  • Tips, Guides and/or Tutorials on writing a Windows desktop app for a PHP programmer by trade 2008-09-26

    Yup, long title. I've been programming in PHP for the last 6 years or so for work and personal projects, but I've got an idea for a desktop app (which incidentally, uses a web REST api). I'm debating on how to approach this - I've got some experience

  • Textual Irregularities 2009-02-06

    Does anybody know of a library or piece of software out there that will locate irregularities in text? For example, lets say I have... 1. Name 1, Comment 2. Name 2, Comment 3. Name 3 , Comment 5. Name 10, Comment This software or library would first

  • interesting Delphi open-source applications/projects (not components/component packs!) 2010-06-15

    I'd like to know what interesting open-source projects written in Delphi (or FreePascal) you know? I'm not asking for components/components packs, I know there were questions for that. Please do not duplicate answers, vote them up instead ;) Please d

  • Firebird RDBMS on Windows embedded compact 7? Alternatives? 2011-03-30

    I need some advice from you. How would you judge running an firebird DBMS on a Windows embedded compact 7 machine? What about ressources? Any other lightweight easy-to-use alternatives for embedded systems? thanks for your advice! --------------Solut

Copyright (C), All Rights Reserved.

processed in 0.142 (s). 11 q(s)