I am designing a debug unit and trying to create a popup menu for use to access debug information.
unit tstDebugPop1;
{.MODE Delphi}
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Menus;
var
fPopMenu1 :TPopupMenu;
gDebug :TStringList;
procedure CreatePopup;
var vItem:TMenuItem;
begin
fPopMenu1:=TPopupMenu.Create(nil);
vItem:=TMenuItem.Create(fPopMenu1);
vItem.Caption:='&Show last';
vItem.OnClick:=@DebugShowLast;
fPopMenu1.Items.Add(vItem);
end;
CreatePopup is executed within the Initialization section of the unit.
An error occurs for the line:
vItem.OnClick:=@DebugShowLast;
and shows the following error:
tstdebugpop1.pas(148,18) Error: Incompatible types: got "Pointer" expected "<procedure variable type of procedure(TObject) of object;Register>"
DebugShowLast is a procedure within the unit.
If I comment out that line, the program runs and the popup menu is created. I link the popup to the main form, and a right click produces the menu with the sole item "Show last". So the creation of the menu and item is working ok, but the link is not.
I have tried the Delphi modes and the {$mode objfpc}{$H+} mode above.
So what is wrong with:
vItem.OnClick:=@DebugShowLast;
TIA