• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Problem setting the menu
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem setting the menu


  • Subject: Problem setting the menu
  • From: "Felipe Monteiro de Carvalho" <email@hidden>
  • Date: Sun, 28 Sep 2008 20:15:54 -0300

Hello,

I am having problems setting a menu for my application. I am writting
the application in Object Pascal and I am not using nib files, because
the point is being able to use this to port cross-platform GUI
libraries.

I create a NSMenu and set it to both AppleMenu and MainMenu, or just 1
of them, but nothing happens!! I always get just an empty menu. I have
read tutorials out there, but according to them this code should work.

I create my menu with this code:

  ....

  MainMenu := CreateMainMenu();

  NSApp.setAppleMenu(MainMenu.Handle);
  NSApp.setMainMenu(MainMenu.Handle);
end;

function TMyView.CreateToolbar(AOwnerView: NSView; AX, AY, AWidth,
  AHeight: Double): NSToolbar;
begin
  Result := NSToolbar.initWithIdentifier(CFEmptyString);
  ToolbarController := TMyToolbarController.Create;
  Result.setDelegate(ToolbarController.Handle);
end;

function TMyView.CreateMainMenu(): NSMenu;
var
  Item1: NSMenuItem;
  MenuTitle: CFStringRef;
begin
  MenuTitle := CFStringCreateWithPascalString(nil, 'Title',
kCFStringEncodingUTF8);
  WriteLn('CreateMenu');
  Result := NSMenu.initWithTitle(MenuTitle);
  WriteLn('Menu Created');

  Item1 := CreateMenuItem('Exit', Str_doClose, myController);
  Result.addItem(Item1.Handle);
end;

function TMyView.CreateMenuItem(ATitle: shortstring;
  ACallbackName: string; ACallbackClass: NSObject): NSMenuItem;
var
  ItemText: CFStringRef;
  KeyText: CFStringRef;
begin
  KeyText := CFStringCreateWithPascalString(nil, '', kCFStringEncodingUTF8);
  ItemText := CFStringCreateWithPascalString(nil, ATitle,
kCFStringEncodingUTF8);
  WriteLn(' ItemText: ', IntToHex(Int64(ItemText), 8), ' ATitle: ', ATitle);

  Result := NSMenuItem.initWithTitle_action_keyEquivalent(ItemText,
nil, KeyText);
  Result.setTarget(ACallbackClass.Handle);
  Result.setAction(sel_registerName(PChar(ACallbackName)));
end;

thanks,
--
Felipe Monteiro de Carvalho
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Problem setting the menu
      • From: Peter Ammon <email@hidden>
  • Prev by Date: Load launchd job immediately, without restart - how?
  • Next by Date: Crash with toolbars
  • Previous by thread: Re: Load launchd job immediately, without restart - how?
  • Next by thread: Re: Problem setting the menu
  • Index(es):
    • Date
    • Thread