Initialize the Menu and Actions

<< Click to Display Table of Contents >>

Navigation:  Create a PDF Editor > Delphi Example >

Initialize the Menu and Actions

Now we add a TWPViewPDFWizard and connect it to the action list and the MainMenu.

 

wpviewed4_2

 

 

Please also add event handlers for

  WPViewPDFWizard1ActionClick and WPViewPDFWizard1ActionUpdate.

 

procedure TForm2.WPViewPDFWizard1ActionClick(Sender: TObject);

begin

  //

end;

 

procedure TForm2.WPViewPDFWizard1ActionUpdate(Sender: TObject);

begin

  //

end;

 

Now please save the form and then double click on the component WPViewPDFWizard1.

 

This will create menu items and action objects which are automatically connected to the ActionClick and ActionUpdate events.

 

To create the actions the method WPPDFViewerInitMainMenu is executed - it is implemented in the unit WPViewPDF4.pas.

 

procedure WPPDFViewerInitMainMenu( pdf : TWPViewPDF;

     Menu : TMainMenu;

     MenuNamePrefix : String;

     ActionList : TActionList; // may be nil

     ActionNamePrefix : String// Prefix, i.e. wpv to create names for the actions

     OnClick : TNotifyEvent;

     OnActionUpdate : TNotifyEvent;

     FileMenu : TMenuItem=nil;

     InfoMenu : TMenuItem=nil;

     DoCreateAction : TWPDoCreateAction = nil;

     RequiredOptionalActions : String = '' );

 

This utility function creates new menu entries. The new menus are inserted before the existing items. The first "File" and the last "Info" menu entry can be specified. They will be extended with new entries.

 

If you pass an ActionList actions will be created there. Those actions will be automatically be used by the newly created menu items.

 

Inside WPPDFViewerInitMainMenu we decided to create standard TAction classes and not special classes. Special classes could save other information, such the command name.

This has the advantage to use standard TActions is: you can cop&paste such actions into different projects, also if WPViewPDF was not installed.

 

When new actions are added to WPViewPDF they will be flagged to be not automatically included in the menu. To include them anyway please add the action name divided by come on parameter RequiredOptionalActions.

 

 

Screenshot of the form after the menu items and actions were created

 

wpviewed4_3

 

 

The new menu items will be created between the menu items in the file menu and the last menu item in the info menu.

The newly created actions will be attached to the the new menu items.

 

Now you can delete the TWPViewPDFWizard, it is not required anymore. The action events will be directly assigned and not passed through the wizard.

 

To compile please also add WPDF_ViewCommands to the uses clause.

 

 

Hint: It is possible to modify the automatically created menu by some code.

 

With this code we modify the menu by moving some items which were initially created under "Extra" under a caption which makes the function easier to find.

 

  for I := 0 to MainMenu1.Items.Count-1 do

  begin

       // We move the "Modify Annotation" item from Special to menu "Annotations"

       if MainMenu1.Items[i].Tag = 6 then

       begin

          AddWeblink1.Parent.Remove(AddWeblink1);

          MainMenu1.Items[i].Add( AddWeblink1 );

 

          Addlinktopage1.Parent.Remove(Addlinktopage1);

          MainMenu1.Items[i].Add( Addlinktopage1 );

 

          men := TMenuItem.Create(MainMenu1.Items[i]);

          men.Caption:='-';

          MainMenu1.Items[i].Add( men );

 

          ModifyAnnotations2.Parent.Remove(ModifyAnnotations2);

          MainMenu1.Items[i].Add( ModifyAnnotations2 );

       end;

       // We move the "Add form field" item from Special to menu "Fields"

       // And also move the add link items

       if MainMenu1.Items[i].Tag = 8 then

       begin

          Addformfield1.Parent.Remove(Addformfield1);

          MainMenu1.Items[i].Add( Addformfield1 );

       end;

  end;