Hi

Attached is a patch that implements a few missing functions (Find,
IsLine) compared to Delphi. Noticed this while porting my Delphi app
to Lazarus.  The patch needs to be applied from the root Lazarus
directory.

Regards,
  - Graeme -


--
There's no place like 127.0.0.1
Index: lcl/include/menuitem.inc
===================================================================
--- lcl/include/menuitem.inc	(revision 8965)
+++ lcl/include/menuitem.inc	(working copy)
@@ -37,8 +37,8 @@
 var
   Item: TMenuItem;
 begin
-  Item:=TMenuItem.Create(Self);
-  Item.Caption:='-';
+  Item := TMenuItem.Create(Self);
+  Item.Caption := cLineCaption;
   Add(Item);
 end;
 
@@ -203,6 +203,19 @@
   inherited Destroy;
 end;
 
+
+{ Find the menu item with a Caption of ACaption. Also for compatability with
+  Delphi. }
+function TMenuItem.Find(const ACaption: string): TMenuItem;
+var
+  Idx: Integer;
+begin
+  Result := nil;
+  Idx := IndexOfCaption(ACaption);
+  if Idx <> -1 then
+    Result := Items[Idx];
+end;
+
 {------------------------------------------------------------------------------
   function TMenuItem.GetImageList: TCustomImageList;
 
@@ -880,6 +893,15 @@
   Result:=Checked or RadioItem or AutoCheck or ShowAlwaysCheckable;
 end;
 
+
+{ Returns true if the current menu item is a Line (menu seperator). Added for
+  Delphi compatability as well. }
+function TMenuItem.IsLine: Boolean;
+begin
+  Result := FCaption = cLineCaption;
+end;
+
+
 {------------------------------------------------------------------------------
   Method:  TMenuItem.SetCaption
   Params:  Value:
Index: lcl/menus.pp
===================================================================
--- lcl/menus.pp	(revision 8965)
+++ lcl/menus.pp	(working copy)
@@ -185,6 +185,7 @@
     FCompStyle: LongInt;
     constructor Create(TheOwner: TComponent); override;
     destructor Destroy; override;
+    function Find(const ACaption: string): TMenuItem;
     function GetImageList: TCustomImageList; virtual;
     function GetParentComponent: TComponent; override;
     function GetParentMenu: TMenu; virtual;
@@ -196,6 +197,7 @@
     function IndexOfCaption(const ACaption: string): Integer; virtual;
     function VisibleIndexOf(Item: TMenuItem): Integer;
     function IsCheckItem: boolean; virtual;
+    function IsLine: Boolean;
     procedure Add(Item: TMenuItem);
     procedure AddSeparator;
     procedure Click; virtual;
@@ -208,7 +210,6 @@
     procedure Clear;
     function HasBitmap: boolean;
     function GetIconSize: TPoint; virtual;
-  public
     // Event lists
     procedure RemoveAllHandlersOfObject(AnObject: TObject); override;
     procedure AddHandlerOnDestroy(const OnDestroyEvent: TNotifyEvent;
@@ -373,6 +374,13 @@
 
 procedure Register;
 
+
+const
+  cHotkeyPrefix   = '&';
+  cLineCaption    = '-';
+  cDialogSuffix   = '...';
+
+
 implementation
 
 uses

Reply via email to