AnnMenu example for Delphi
var
//Global declarations
RasterAnn: LEADRasterAnnotation;
RasterAnnToolbar: LEADRasterAnnToolBar;
procedure TForm1.Button1Click(Sender: TObject);
begin
RasterAnn:= CoLEADRasterAnnotation.Create ();
RasterAnnToolbar:= CoLEADRasterAnnToolBar.Create ();
RasterAnn.AnnParentRasterView := LEADRasterView1.Raster;
LEADEventSink1.Connect (RasterAnn, _LEADRasterAnnotationEvents);
RasterAnn.AnnUserMode:= ANN_USERMODE_DESIGN;
end;
procedure TForm1. LEADEventSink1Invoke(Sender: TObject; DispID: Integer;
const IID: TGUID; LocaleID: Integer; Flags: Word; Params: tagDISPPARAMS;
varResult, ExcepInfo, ArgErr: Pointer);
var
szout: String;
nID: Integer;
hMenu: OleVariant;
RasAnnMenu: LEADRasterAnnMenu;
AnnPopupMenu: LEADRasterAnnMenu;
x: Integer;
begin
case (DispID) of
LEADRASTERANNOTATIONEVENTS_ANNMENU:
begin
hMenu:= OleVariant(Params.rgvarg^[0]);
RasAnnMenu:= CreateComObject(CLASS_LEADRasterAnnMenu)as LEADRasterAnnMenu;
RasAnnMenu.SetAnnMenu (hMenu);
RasAnnMenu.EnableMethodErrors:= False;
szout:= 'There are ' + IntToStr(RasAnnMenu.Count) + ' Items';
ShowMessage (szout);
szout:= 'Original Text for item#2: ';
szout:= szout + RasAnnMenu.ItemString [1];
ShowMessage (szout);
//set new string
RasAnnMenu.ItemString[1]:= 'TestText';
szout := 'Custom Text for item#2: ';
szout := szout + RasAnnMenu.ItemString[1];
ShowMessage (szout);
//make 3rd and 4th menu items have the same command id
nID := RasAnnMenu.ItemID [3];
RasAnnMenu.ItemID[2]:= nID;
//check all unchecked menu items that are not popup submenus
//disable all enabled menu items that are not popup submenus
for x := 0 to RasAnnMenu.Count do
begin
if (RasAnnMenu.ItemType [x]= ANN_MENUITEMTYPE_NORMAL) then
begin
if (RasAnnMenu.ItemChecked [x]) then
RasAnnMenu.ItemChecked[x]:= True;
if (RasAnnMenu.ItemEnabled [x]) then
RasAnnMenu.ItemEnabled[x]:= False;
end;
end;
//insert 2 user-defined menu items
RasAnnMenu.AddItem ('Test&1', ANN_MENUITEMTYPE_NORMAL, ANN_EVENT_MENUFIRST + 0, RasAnnMenu.Count - 1);
RasAnnMenu.AddItem ('Test&2', ANN_MENUITEMTYPE_NORMAL, ANN_EVENT_MENUFIRST + 1, RasAnnMenu.Count - 1);
//delete the last menu item
RasAnnMenu.DeleteItem (RasAnnMenu.Count - 1);
//delete the first menu item
RasAnnMenu.DeleteItem (0);
//insert a popup menu
RasAnnMenu.AddItem ('Popup', ANN_MENUITEMTYPE_SUBMENU, 0, RasAnnMenu.Count);
//get the new item, and add some items to it
RasAnnMenu.GetSubMenu (RasAnnMenu.Count - 1, AnnPopupMenu);
AnnPopupMenu.AddItem ('Popup&1', ANN_MENUITEMTYPE_NORMAL, ANN_EVENT_MENUFIRST + 2, AnnPopupMenu.Count);
AnnPopupMenu.AddItem ('Popup&2', ANN_MENUITEMTYPE_NORMAL, ANN_EVENT_MENUFIRST + 3, AnnPopupMenu.Count);
end;
LEADRASTERANNOTATIONEVENTS_ANNUSERMENU:
begin
nID:= OleVariant(Params.rgvarg^[0]);
if (nID = ANN_EVENT_MENUFIRST) then
RasterAnn.AnnFlip (False, 0, True)
else
ShowMessage ('nID = ANN_EVENT_MENUFIRST + ' + IntToStr(nID - ANN_EVENT_MENUFIRST));
end;
end;
end;