summaryrefslogtreecommitdiff
path: root/examples/gui/command_interface/commands.pas
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2007-11-29 08:54:34 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2007-11-29 08:54:34 +0000
commit709237f47fd404fc163ca5f2d7532f08647a9e05 (patch)
treed7fd6dab9ae4a538369cb76ae8ee35bbea5ff159 /examples/gui/command_interface/commands.pas
parent9eb3c0612e792949d450509236bf12500c559eb6 (diff)
downloadfpGUI-709237f47fd404fc163ca5f2d7532f08647a9e05.tar.xz
* 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.
Diffstat (limited to 'examples/gui/command_interface/commands.pas')
-rw-r--r--examples/gui/command_interface/commands.pas90
1 files changed, 90 insertions, 0 deletions
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.
+