macoslib Code Review - please.

Hi,
I have the code below in Window1, and all works perfectly.

[code] // INSTANTIATE A NEW TOOLBAR ITEM
t = new NSToolbar(“com.richard.toolbar3”, addressOf ToolbarAction)

// SPECIFY THE DEFAULT ITEMS
t.DefaultItems = array(NSToolbarSpaceItemIdentifier, “CREATE”, NSToolbarSpaceItemIdentifier, “DELETE”, NSToolbarFlexibleSpaceItemIdentifier, NSSearchField1.name)

// SPECIFY THE ALLOWED ITEMS
t.AllowedItems = array(“CREATE”, “DELETE”, NSSearchField1.name)

// ADD SEARCH FIELD
tc = new NSToolbarCustomItem(NSSearchField1)
tc.itemLabel = “SEARCH”

// ADD NSSEARCHFIELD TO THE TOOLBAR
t.addItem tc[/code]

I then put exactly the same code in Window2, but I get the following error message:

Any ideas what I am doing wrong???

Drag a Canvas onto Window2, name it “NSSearchField1” then change its super to Cocoa.NSSearchField.

Jason, thanks - I will try that, but in the meantime, could you explain why I need a canvas in Window2, if I don’t need one in Window1??

I am just trying to learn why, as opposed to following blindly and not knowing why I am doing it :slight_smile:

Thank you very much!

Its because you need to have an NSSearchField on the window to use it in the toolbar as you are. Since NSSearchField descends from canvas, a good way to add one to the window is to add a canvas and change its super.

Thank you very much Jason - much appreciated :slight_smile: