Method pointer and regular procedure incompatible

后端 未结 5 850
谎友^
谎友^ 2020-12-14 03:27

I have an app, which has multiple forms. All these forms have a PopupMenu. I build the menu items programatically, all under a common root menu item. I want ALL the menu

5条回答
  •  情歌与酒
    2020-12-14 03:53

    You could choose one of these:

    1. Derive your forms from a common ancestor and declare the method in it so it's available to descendants
    2. Use a global instance of a class (e.g. data module) shared by all forms
    3. Use a procedure as a fake method like this:

    procedure MyClick(Self, Sender: TObject);
    begin
      //...
    end;
    
    var
      M: TMethod;
    begin
      M.Data := nil;
      M.Code := @MyClick;
      MyMenuItem.OnClick := TNotifyEvent(M);
    end;
    

提交回复
热议问题