lazarus中不同模式下自定义函数的调用方式区别

    1、在{$mode objfpc}{$H+}   方式下自定函数:

private

......

    // 显示定制crud界面
    procedure showCrudForm(Sender: TObject);   

......


调用:

...

crudItem.OnClick := @showCrudForm;    

...


    2、在 {$mode delphi}   方式下自定函数:

private

......

    // 显示定制crud界面
    procedure showCrudForm(Sender: TObject);   

......


调用:

...

crudItem.OnClick := showCrudForm;  

......


============================================


unit dy224;

//{$MODE Delphi}
{$mode objfpc}{$H+}



interface

uses
  LCLIntf, LCLType, LMessages, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls;

type
  TForm1 = class(TForm)
    procedure FormDestroy(Sender: TObject);
     procedure ShowHandlerCount(Sender: TObject; Msg: Cardinal);
     procedure FormCreate(Sender: TObject);
   private
     HandlerCount: integer;
     function GetMsgName(aMsg: integer): string;
   end;


var
  Form1: TForm1;


implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Application.RemoveOnUserInputHandler(@ShowHandlerCount);
end;

procedure TForm1.ShowHandlerCount(Sender: TObject; Msg: Cardinal);
var
  nm: string;
begin
  nm:=GetMsgName(msg);
  Caption:=Format('Count: %d, Msg: %d (%s)',[HandlerCount, Msg, nm]);
  Inc(HandlerCount);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.AddOnUserInputHandler(@ShowHandlerCount);
end;

function TForm1.GetMsgName(aMsg: integer): string;
begin
  case aMsg of    // incomplete listing ...
    0: Result:='WM_THEMECHANGED';
		  1: Result:='WM_CREATE';
		  2: Result:='WM_NCMOUSELEAVE';
		  3: Result:='WM_MOVE';
		  5: Result:='WM_SIZE';
		  6: Result:='WM_ACTIVATE';
		  7: Result:='WM_SETFOCUS';
		  8: Result:='WM_KILLFOCUS';
		  10: Result:='WM_ENABLE';
		  11: Result:='WM_SETREDRAW';
		  12: Result:='WM_SETTEXT';
		  13: Result:='WM_GETTEXT';
		  14: Result:='WM_GETTEXTLENGTH';
		  15: Result:='WM_PAINT';
		  16: Result:='WM_CLOSE';
		  17: Result:='WM_QUERYENDSESSION';
		  18: Result:='WM_QUIT';
		  19: Result:='WM_QUERYOPEN';
		  20: Result:='WM_ERASEBKGND';
		  21: Result:='WM_SYSCOLORCHANGE';
		  22: Result:='WM_ENDSESSION';
		  24: Result:='WM_SHOWWINDOW';
		  26: Result:='WM_WININICHANGE';
		  27: Result:='WM_DEVMODECHANGE';
		  28: Result:='WM_ACTIVATEAPP';
		  29: Result:='WM_FONTCHANGE';
		  30: Result:='WM_TIMECHANGE';
		  31: Result:='WM_CANCELMODE';
		  32: Result:='WM_SETCURSOR';
		  33: Result:='WM_MOUSEACTIVATE';
		  34: Result:='WM_CHILDACTIVATE';
		  35: Result:='WM_QUEUESYNC';
		  36: Result:='WM_GETMINMAXINFO';
		  38: Result:='WM_PAINTICON';
		  39: Result:='WM_ICONERASEBKGND';
		  40: Result:='WM_NEXTDLGCTL';
		  42: Result:='WM_SPOOLERSTATUS';
		  43: Result:='WM_DRAWITEM';
		  44: Result:='WM_MEASUREITEM';
		  45: Result:='WM_DELETEITEM';
		  46: Result:='WM_VKEYTOITEM';
		  47: Result:='WM_CHARTOITEM';
		  48: Result:='WM_SETFONT';
		  49: Result:='WM_GETFONT';
		  50: Result:='WM_SETHOTKEY';
		  51: Result:='WM_GETHOTKEY';
		  55: Result:='WM_QUERYDRAGICON';
		  57: Result:='WM_COMPAREITEM';
		  65: Result:='WM_COMPACTING';
		  70: Result:='WM_WINDOWPOSCHANGING';
		  71: Result:='WM_WINDOWPOSCHANGED';
		  72: Result:='WM_POWER';
		  74: Result:='WM_COPYDATA';
		  75: Result:='WM_CANCELJOURNAL';
		  78: Result:='WM_NOTIFY';
		  80: Result:='WM_INPUTLANGCHANGEREQUEST';
		  81: Result:='WM_INPUTLANGCHANGE';
		  82: Result:='WM_TCARD';
		  83: Result:='WM_HELP';
		  84: Result:='WM_USERCHANGED';
		  85: Result:='WM_NOTIFYFORMAT';
		  123: Result:='WM_CONTEXTMENU';
		  124: Result:='WM_STYLECHANGING';
		  125: Result:='WM_STYLECHANGED';
		  126: Result:='WM_DISPLAYCHANGE';
		  127: Result:='WM_GETICON';
		  128: Result:='WM_SETICON';
		  129: Result:='WM_NCCREATE';
		  130: Result:='WM_NCDESTROY';
		  131: Result:='WM_NCCALCSIZE';
		  132: Result:='WM_NCHITTEST';
		  133: Result:='WM_NCPAINT';
		  134: Result:='WM_NCACTIVATE';
		  135: Result:='WM_GETDLGCODE';
		  160: Result:='WM_NCMOUSEMOVE';
		  161: Result:='WM_NCLBUTTONDOWN';
		  162: Result:='WM_NCLBUTTONUP';
		  163: Result:='WM_NCLBUTTONDBLCLK';
		  164: Result:='WM_NCRBUTTONDOWN';
		  165: Result:='WM_NCRBUTTONUP';
		  166: Result:='WM_NCRBUTTONDBLCLK';
		  167: Result:='WM_NCMBUTTONDOWN';
		  168: Result:='WM_NCMBUTTONUP';
		  169: Result:='WM_NCMBUTTONDBLCLK';
		  256: Result:='WM_KEYDOWN';
		  257: Result:='WM_KEYUP';
		  258: Result:='WM_CHAR';
		  259: Result:='WM_DEADCHAR';
		  260: Result:='WM_SYSKEYDOWN';
		  261: Result:='WM_SYSKEYUP';
		  262: Result:='WM_SYSCHAR';
		  263: Result:='WM_SYSDEADCHAR';
		  265: Result:='WM_UNICHAR';
		  269: Result:='WM_IME_STARTCOMPOSITION';
		  270: Result:='WM_IME_ENDCOMPOSITION';
		  271: Result:='WM_IME_COMPOSITION';
		  272: Result:='WM_INITDIALOG';
		  273: Result:='WM_COMMAND';
		  274: Result:='WM_SYSCOMMAND';
		  275: Result:='WM_TIMER';
		  276: Result:='WM_HSCROLL';
		  277: Result:='WM_VSCROLL';
		  278: Result:='WM_INITMENU';
		  279: Result:='WM_INITMENUPOPUP';
		  281: Result:='WM_GESTURE';
		  287: Result:='WM_MENUSELECT';
		  288: Result:='WM_MENUCHAR';
		  289: Result:='WM_ENTERIDLE';
		  290: Result:='WM_MENURBUTTONUP';
		  291: Result:='WM_MENUDRAG     ';
		  292: Result:='WM_MENUGETOBJECT';
		  293: Result:='WM_UNINITMENUPOPUP';
		  294: Result:='WM_MENUCOMMAND';
		  306: Result:='WM_CTLCOLORMSGBOX';
		  307: Result:='WM_CTLCOLOREDIT';
		  308: Result:='WM_CTLCOLORLISTBOX';
		  309: Result:='WM_CTLCOLORBTN';
		  310: Result:='WM_CTLCOLORDLG';
		  311: Result:='WM_CTLCOLORSCROLLBAR';
		  312: Result:='WM_CTLCOLORSTATIC';
		  512: Result:='WM_MOUSEMOVE';
		  513: Result:='WM_LBUTTONDOWN';
		  514: Result:='WM_LBUTTONUP';
		  515: Result:='WM_LBUTTONDBLCLK';
		  516: Result:='WM_RBUTTONDOWN';
		  517: Result:='WM_RBUTTONUP';
		  518: Result:='WM_RBUTTONDBLCLK';
		  519: Result:='WM_MBUTTONDOWN';
		  520: Result:='WM_MBUTTONUP';
		  521: Result:='WM_MBUTTONDBLCLK';
		  522: Result:='WM_MOUSEWHEEL';
		  528: Result:='WM_PARENTNOTIFY';
		  529: Result:='WM_ENTERMENULOOP';
		  530: Result:='WM_EXITMENULOOP';
		  532: Result:='WM_SIZING';
		  533: Result:='WM_CAPTURECHANGED';
		  534: Result:='WM_MOVING';
		  536: Result:='WM_POWERBROADCAST';
		  537: Result:='WM_DEVICECHANGE';
		  544: Result:='WM_MDICREATE';
		  545: Result:='WM_MDIDESTROY';
		  546: Result:='WM_MDIACTIVATE';
		  547: Result:='WM_MDIRESTORE';
		  548: Result:='WM_MDINEXT';
		  549: Result:='WM_MDIMAXIMIZE';
		  550: Result:='WM_MDITILE';
		  551: Result:='WM_MDICASCADE';
		  552: Result:='WM_MDIICONARRANGE';
		  553: Result:='WM_MDIGETACTIVE';
		  560: Result:='WM_MDISETMENU';
		  561: Result:='WM_ENTERSIZEMOVE';
		  562: Result:='WM_EXITSIZEMOVE';
		  563: Result:='WM_DROPFILES';
		  564: Result:='WM_MDIREFRESHMENU';
		  641: Result:='WM_IME_SETCONTEXT';
		  642: Result:='WM_IME_NOTIFY';
		  643: Result:='WM_IME_CONTROL';
		  644: Result:='WM_IME_COMPOSITIONFULL';
		  645: Result:='WM_IME_SELECT';
		  646: Result:='WM_IME_CHAR';
		  648: Result:='WM_IME_REQUEST';
		  656: Result:='WM_IME_KEYDOWN';
		  657: Result:='WM_IME_KEYUP';
		  673: Result:='WM_MOUSEHOVER';
		  675: Result:='WM_MOUSELEAVE';
		  768: Result:='WM_CUT';
		  769: Result:='WM_COPY';
		  770: Result:='WM_PASTE';
		  771: Result:='WM_CLEAR';
		  772: Result:='WM_UNDO';
		  773: Result:='WM_RENDERFORMAT';
		  774: Result:='WM_RENDERALLFORMATS';
		  775: Result:='WM_DESTROYCLIPBOARD';
		  776: Result:='WM_DRAWCLIPBOARD';
		  777: Result:='WM_PAINTCLIPBOARD';
		  778: Result:='WM_VSCROLLCLIPBOARD';
		  779: Result:='WM_SIZECLIPBOARD';
		  780: Result:='WM_ASKCBFORMATNAME';
		  781: Result:='WM_CHANGECBCHAIN';
		  782: Result:='WM_HSCROLLCLIPBOARD';
		  783: Result:='WM_QUERYNEWPALETTE';
		  784: Result:='WM_PALETTEISCHANGING';
		  785: Result:='WM_PALETTECHANGED';
		  786: Result:='WM_HOTKEY';
		  791: Result:='WM_PRINT';
		  792: Result:='WM_PRINTCLIENT';
		  793: Result:='WM_APPCOMMAND ';
		  816: Result:='WM_MEASURECONTROL';
		  817: Result:='WM_GETACTIONTEXT ';
		  896: Result:='WM_PENWINFIRST';
		  911: Result:='WM_PENWINLAST';
		  1024: Result:='WM_USER';
		  1025: Result:='WM_PSD_FULLPAGERECT';
		  1026: Result:='WM_PSD_MINMARGINRECT';
		  1027: Result:='WM_PSD_MARGINRECT';
		  1028: Result:='WM_PSD_GREEKTEXTRECT';
		  1029: Result:='WM_PSD_ENVSTAMPRECT';
		  1030: Result:='WM_PSD_YAFULLPAGERECT';
		  1125: Result:='WM_CHOOSEFONT_SETLOGFONT';
		  1126: Result:='WM_CHOOSEFONT_SETFLAGS';
		  32768: Result:='WM_APP';
    else Result:=Format('Unknown message 0x%x (%d)', [aMsg, aMsg]);
  end;
  Result:=Trim(Result);
end;

end.


你可能感兴趣的:(自定义函数,Lazarus)