Examples Delphi

Title: Rudimentary Menu Plug In Mechanism
Question: How to define your menu plug ins using text file and create them at runtime.
Answer:
Rudimentary Menu Plug In Mechanism
Sometimes we need to be able to add plug ins to an application. One of the tasks for making plug ins is defining menu items for plug ins. In this example the menu plug ins definition is stored in a text file which resides in the same directory with the application. Each line of the text file represents one menu item. The syntax for the menu item line is:
[]
shortcut string syntax:
none|[...]+
Here's an example for the menu text file:
*;Menu Item One;none
**;Menu Item Two;none
***;Menu Item Three;ctrl+N;Notepad.exe
***;Menu Item Four;ctrl+E;Explorer.exe
***;Menu Item Five;ctrl+L;Calc.exe
**;Menu Item Six;none;Notepad.exe
*;Menu Item Seven;none;Explorer.exe
The asterisk(s) shows the hierarchy of the menu items. Menu item three, four and five are submenus of menu item two. Menu item two and six are submenus of menu item one. Menu item one and seven are submenus of menu item where you want to put the plug ins.
The menu items file will be read inside this procedure:
procedure FormPluginMenu(AForm:TForm;ParentMenu:TMenuItem;
MenuClick:TNotifyEvent;CmdList:TStrings);
AForm is the form which owns the plug ins.
ParentMenu is the menu item where you put the plug ins.
MenuClick is the event handler for plug ins menu item.
CmdList is the string list of the plug ins command.
Below is an example of plug in menu item click event handler. The event handler knows the right command using Sender's Tag property as an index.
procedure TfrmMain.PluginClick(Sender: TObject);
begin
with TMenuItem(Sender) do
RunFile(CmdList[Tag],'','',SW_SHOW);
end;
I didn't use a sophisticated scanner or parser method for this so the syntax is a strict syntax. I will send the project files to webmaster so he can uploads them later.