{*******************************************************}
{                                                       }
{       Pascal Script Source File                       }
{       Run by RemObjects Pascal Script in CnWizards    }
{                                                       }
{       Generated by CnPack IDE Wizards                 }
{                                                       }
{*******************************************************}

program AddMenuItem;

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

procedure MenuClick(Sender: TObject);
begin
  ShowMessage('CnPack Menu Clicked!');
end;

var
  Menu: TMenuItem;
  MainForm: TCustomForm;
  Component: TComponent;
begin
  MainForm := GetIdeMainForm;
  if MainForm <> nil then
  begin
    Component := MainForm.FindComponent('HelpMenu');
    if Component = nil then
    begin
      ErrorDlg('Help Menu NOT Found.');
      Exit;
    end;

    Menu := TMenuItem(Component.FindComponent('CnPackMenu'));
    if Menu <> nil then
    begin
      ErrorDlg('CnPack Menu Already Exists. To Delete It.');
      Menu.Free;
      Exit;
    end;

    Menu := TMenuItem.Create(Component);
    Menu.Name := 'CnPackMenu';
    Menu.Caption := '&CnPack Menu';
    TMenuItem(Component).Add(Menu);

    Menu.OnClick := @MenuClick;
  end;
end.

 