home *** CD-ROM | disk | FTP | other *** search
- Listing One
-
- unit Importer;
-
- { This is an add-in Delphi expert to display the dynamic imports
- needed by the current project's EXE file.
- (c)1997 Dave Jewell, All rights reserved.
- }
-
- interface
-
- uses Windows, SysUtils, Classes, ExptIntf, ToolIntf, Dialogs;
-
- type
- TProjectOpenCloseEvent = procedure (Sender: TObject; Opening: Boolean) of Object;
-
- { Custom notifier for Import Export }
- TImportNotifier = class (TIAddInNotifier)
- public
- Hook: TProjectOpenCloseEvent;
- constructor Create;
- destructor Destroy; override;
- procedure EventNotification (NotifyCode: TEventNotification;
- var Cancel: Boolean); override;
- procedure FileNotification (NotifyCode: TFileNotification;
- const FileName: String; var Cancel: Boolean); override;
- end;
-
- TImportExpert = class (TIExpert)
- public
- function GetName: string; override;
- function GetAuthor: string; override;
- function GetComment: string; override;
- function GetPage: string; override;
- function GetGlyph: hIcon; override;
- function GetStyle: TExpertStyle; override;
- function GetState: TExpertState; override;
- function GetIDString: string; override;
- function GetMenuText: string; override;
- procedure Execute; override;
- constructor Create;
- destructor Destroy; override;
- procedure MenuClick (Sender: TIMenuItemIntf);
- procedure ProjectNotify (Sender: TObject; Opening: Boolean);
- private
- MyMenuItem: TIMenuItemIntf;
- MyNotifier: TImportNotifier;
- end;
-
- implementation
-
- resourcestring
- idAuthor = 'Dave''s ExpertWare Inc.';
- idName = 'Import Expert';
- idMenuText = 'Project Imports';
- idMenuName = 'ImportMenuItem';
-
- { TImportNotifier }
-
- constructor TImportNotifier.Create;
- begin
- Inherited Create;
- ToolServices.AddNotifierEx (Self);
- end;
-
- destructor TImportNotifier.Destroy;
- begin
- ToolServices.RemoveNotifier (Self);
- Inherited Destroy;
- end;
-
- procedure TImportNotifier.EventNotification (NotifyCode: TEventNotification;
- var Cancel: Boolean);
- begin
- { I'm not interested in event notifications }
- end;
-
- procedure TImportNotifier.FileNotification (NotifyCode: TFileNotification;
- const FileName: String; var Cancel: Boolean);
- begin
- { Note: fnProjectClosing is not foolproof - see text }
- if Assigned (Hook) and (NotifyCode in [fnProjectOpened, fnProjectClosing]) then
- Hook (Self, NotifyCode = fnProjectOpened);
- end;
-
- { TImportExpert }
-
- constructor TImportExpert.Create;
- var
- Target, Parent: TIMenuItemIntf;
- begin
- Inherited Create;
- with ToolServices.GetMainMenu do
- try
- Target := FindMenuItem ('ViewPrjSourceItem');
- if Target <> nil then
- try
- Parent := Target.GetParent;
- if Parent <> nil then
- try
- MyMenuItem := Parent.InsertItem (Target.GetIndex + 1,
- idMenuText, idMenuName, '', 0, 0, 0,
- [mfEnabled, mfVisible], MenuClick);
- finally
- Parent.Free;
- end;
- finally
- Target.Free;
- end;
- finally
- Free;
- end;
-
- MyNotifier := TImportNotifier.Create;
- MyNotifier.Hook := ProjectNotify;
- end;
-
- destructor TImportExpert.Destroy;
- begin
- MyMenuItem.Free;
- MyNotifier.Free;
- Inherited Destroy;
- end;
-
- function TImportExpert.GetName: string;
- begin Result := idName; end;
-
- function TImportExpert.GetAuthor: string;
- begin Result := ''; end;
-
- function TImportExpert.GetComment: string;
- begin Result := ''; end;
-
- function TImportExpert.GetPage: string;
- begin Result := ''; end;
-
- function TImportExpert.GetGlyph: hIcon;
- begin Result := 0; end;
-
- function TImportExpert.GetStyle: TExpertStyle;
- begin Result := esAddIn; end;
-
- function TImportExpert.GetState: TExpertState;
- begin Result := []; end;
-
- function TImportExpert.GetIDString: string;
- begin Result := idAuthor + idName; end;
-
- function TImportExpert.GetMenuText: string;
- begin Result := ''; end;
-
- procedure TImportExpert.Execute;
- begin end;
-
- procedure TImportExpert.ProjectNotify (Sender: TObject; Opening: Boolean);
- begin
- if Opening then MyMenuItem.SetFlags ([mfEnabled], [mfEnabled])
- else MyMenuItem.SetFlags ([mfEnabled], []);
- end;
-
- procedure TImportExpert.MenuClick (Sender: TIMenuItemIntf);
- begin
- ShowMessage ('Watch this space...');
- end;
-
- end.
-