Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi







Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (3)


Rudimentary Menu Plug In MechanismGo to Alex Wijoyo's websiteComponent available for this articleFormat this article printer-friendly!Bookmark function is only available for registered users!
Define your menu plug ins using text file and create them at runtime
Product:
Delphi all versions
Category:
Others
Skill Level:
Scoring:
Last Update:
07/16/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet plug-in plugin menu
Times Scored:
2
Visits:
3189
Uploader: Alex Wijoyo
Company: Excellont
Reference: N/A
Component Download: ../article/3319/MenuPlugin.zip
 
Question/Problem/Abstract:
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.





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
good
    F C (Oct 18 2004 11:50PM)

I like your way of doing things, don't use XML.

XML is useless for the general programmer/user..
XML is a nice idea in theory to soem people, but essentially it's a waste of time.
Respond

Nice train of thought
    Mat Hobbs (Jul 25 2002 3:26AM)

Hi,

I like the way your brain is thinking. :)

Maybe use an XML format instead if you were
going to write a component for public use.

This could be extended to allow new menu items to
run batch commands on the app instead of just
calling external programs.  Though the app would
then have to define the commands in advance.

E.g. a menu item to open a specific file, print it,
and then close it...

Cheers,
-Mat

Respond

RE: Nice train of thought
Alex Wijoyo (Jul 25 2002 12:33PM)

Hi Matt,
Thank you for your comment.
I do understand the best format for storing hierarchial data is XML. But I hate to edit an XML document using a text editor. I believe an ordinary user will hate it more than I do.
My example for running external apps keeps the example simple. You can use this for complex plugin mechanism using .BPL file, inheritance and runtime class registration. I use this mechanism for adding report plugins.
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
S. Carter
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)