finally, we need to add some functionality to the custommodule class. to register the actions supported, you nedd to call the registeraction method inside the overridden registeractions method. the isactionsupported method returns whether the action is supported or not. override updateactionsstate to change the action's enabled and isdown properties.
here is the interface section of the modified custommodule.pas unit:
| [delphi] unit custommodule; interface uses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, actnlist; type tactionnotification = procedure(action: tbasicaction) of object; tfrmcustommodule = class(tframe) private // the list of supported actions fsupportedactionlist: tlist; fondestroy: tnotifyevent; // returns the event handler for the action function getnotificationbyaction(action: tbasicaction): tactionnotification; protected // register the supported action procedure registeraction(const action: tbasicaction; anotification: tactionnotification); // the descendant classes have to override this method to register supported actions procedure registeractions; virtual; public constructor create(aowner: tcomponent); override; destructor destroy; override; // override the base tframe's executeaction behaviour function executeaction(action: tbasicaction): boolean; override; // returns true if the module supports the action function isactionsupported(action: tbasicaction): boolean; // make all supported actions visible and unsupported actions invisible on module activation procedure updateactionsvisibility; virtual; // updates action states procedure updateactionsstate; virtual; property ondestroy: tnotifyevent read fondestroy write fondestroy; end; tfrmcustommoduleclass = class of tfrmcustommodule; |
here is the small example of using actions in a tfrmcustommodule descendant
| [delphi] unit module1; interface uses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, custommodule, stdctrls, modules; type //the module has to be inherited from the custom module class tfrmmodule1 = class(tfrmcustommodule) label1: tlabel; checkbox1: tcheckbox; label2: tlabel; edit1: tedit; procedure checkbox1click(sender: tobject); private // handler for action1 procedure doaction1(action: tbasicaction); protected // register supported actions procedure registeractions; override; public // update action states procedure updateactionsstate; override; end; implementation uses dmactions; {$r *.dfm} { tfrmmodule1 } procedure tfrmmodule1.registeractions; begin inherited registeractions; // register action1 into the supported actions list registeraction(appactions.action1, doaction1); end; procedure tfrmmodule1.updateactionsstate; begin inherited updateactionsstate; // make action1 enabled if checkbox1 is unchecked appactions.action1.enabled := not checkbox1.checked; end; // show the times that action1 has been performed in edit1 procedure tfrmmodule1.doaction1(action: tbasicaction); begin edit1.text := inttostr(strtoint(edit1.text) + 1); end; procedure tfrmmodule1.checkbox1click(sender: tobject); begin updateactionsstate; end; initialization // register the class within our application framework moduleinfomanager.registermodule('module1', tfrmmodule1, 0, 0); end. |
summary

here is the link to the source code of the application written in delphi.
improving the application framework by using developer express components
add developer express navbar control
we created the first version of the application framework in the previous step and it works fine from our point of view. however, if we were to show it to the boss or our end-user, they would laugh at us. a listbox is not the best choice for a navigation control in modern applications since windows users expect state of the art ui controls. developer express provides the expressnavbar control with over ten different paint styles to enhance the display. it will allow you to give your application a modern look.
the navbar library has easy to use designers that will help you to set up the control at design-time. unfortunately however, we have to forget the designers and do everything by code since the main module must not know about the modules we are going to introduce into the system (and we want to manage modules by adding/removing a single line of code).
first, we have to introduce additional features into our application framework. navbar controls divide items into categories, so we have to introduce categories into our module registration classes. furthermore, we want to have images for items and groups in the navbar control, as it will radically improve the look of the application. thus, we need to introduce image properties in our registration classes also.
here are the changes that we have to do in the modules.pas unit:
add class tcategoryinfo
| [delphi] // contains information about the category tcategoryinfo = class private fname: string; fimageindex: integer; function getindex: integer; public constructor create(aname: string; aimageindex: integer); property index: integer read getindex; property imageindex: integer read fimageindex; property name: string read fname; end; |