From 709237f47fd404fc163ca5f2d7532f08647a9e05 Mon Sep 17 00:00:00 2001 From: graemeg Date: Thu, 29 Nov 2007 08:54:34 +0000 Subject: * Created a new overloaded CentrePoint function. * Implemented a new method TfpgPopupMenu.MenuItemByName * Created a example project showing how the ICommand and ICommandHolder interfaces can be used. --- examples/gui/command_interface/commands.pas | 90 +++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 examples/gui/command_interface/commands.pas (limited to 'examples/gui/command_interface/commands.pas') diff --git a/examples/gui/command_interface/commands.pas b/examples/gui/command_interface/commands.pas new file mode 100644 index 00000000..2824a04d --- /dev/null +++ b/examples/gui/command_interface/commands.pas @@ -0,0 +1,90 @@ +{ + Here we define some commands that can be reused throughout a application. + Command actions are kept separate from the UI code (Forms). +} +unit commands; + +{$mode objfpc}{$H+} +{$INTERFACES CORBA} + +interface + +uses + gfx_command_intf, + gui_memo; + +type + // non reference counted interface + TNullInterfacedObject = class(TObject) + protected + function QueryInterface(const IID: TGUID; out Obj): longint; stdcall; + function _AddRef: longint; stdcall; + function _Release: longint; stdcall; + end; + + + TAddCommand = class(TInterfacedObject, ICommand) + private + FMemo: TfpgMemo; + public + constructor Create(AMemo: TfpgMemo); reintroduce; + procedure Execute; + end; + + + TExitCommand = class(TInterfacedObject, ICommand) + public + procedure Execute; + end; + + +implementation + +uses + fpgfx, SysUtils; + +{ TNullInterfacedObject } + +function TNullInterfacedObject.QueryInterface(const IID: TGUID; out Obj): longint; stdcall; +begin + if GetInterface(IID, Obj) then + Result := 0 + else + result := integer(e_nointerface); +end; + +function TNullInterfacedObject._AddRef: longint; stdcall; +begin + Result := -1; +end; + +function TNullInterfacedObject._Release: longint; stdcall; +begin + Result := -1; +end; + +{ TAddCommand } + +constructor TAddCommand.Create(AMemo: TfpgMemo); +begin + inherited Create; + FMemo := AMemo; +end; + +procedure TAddCommand.Execute; +begin + Writeln('>> TAddComand.Execute'); + FMemo.Lines.Add('Hello ' + IntToStr(Random(500))); + FMemo.Invalidate; +end; + +{ TExitCommand } + +procedure TExitCommand.Execute; +begin + Writeln('>> TExitComand.Execute'); + fpgApplication.Terminated := True; +end; + +end. + -- cgit v1.2.3-70-g09d2