Frustrated by Combo Box

G’day scripters

I’m trying to get the typed in item from a Combo Box and finding it difficult.

I want the user to be able to build a list of email addresses, but can’t even get the first typed in address.

I’ve tried lots of items from the book ‘Cocoa in a Nutshell’ as well as some from the Developer notes, but nada.

Can anyone give me some clues as to what I need to do to proceed please.

Regards

Santa


on SetCCMailRecipients_(sender)
		try
			set SelectedUser to (CCMailRecipients's itemObjectValueAtIndex_(0)) as text
			display dialog SelectedUser
		on error errmsg
			display dialog errmsg
		end try
	end SetCCMailRecipients_

Hi,

you can get the text in the text field with (assuming NSComboBox *comboBox; exists)

[comboBox stringValue];

to populate the list you can use a datasource or insert the text field object with

[comboBox insertItemWithObjectValue:[comboBox stringValue] atIndex:0];

G’day Stefan, and thanks for your reply.

Unfortunately I can’t get it to work. t errors with ‘no value for t’ when i enter something into the combo box ‘CCMailRecipients’. I don’t know enough about Studio to understand what I’m doing wrong, and hours of reading haven’t helped.

Regards

Santa


on SetCCMailRecipients_(sender)
		try
			set t to CCMailRecipients's stringValue_()
			--set SelectedUser to (CCMailRecipients's objectValues()) as list
			display dialog t
		on error errmsg
			display dialog errmsg
		end try
	end SetCCMailRecipients_

I don’t know much about AppleScriptObjC but as stringValue has no parameter isn’t it

stringValue()

Thanks Stefan, I wasn’t sure, but that doesn’t work either.

Either I’m doing something wrong, or stringValue() isn’t working like it’s supposed to.

Regards

Santa

G’day

Every things OK, I re-inserted the ComboBox and re-built the bindings, to no avail. I created a new project just with a combobox and pasted the script in, nada.

I changed the routines title ‘SetCCMailRecipients_’ to a shorter one and rebuilt the bindings and what do you know, it works!

Is there a limit on the title length for routines?

Regards

Santa

No, one of the longest method names in Cocoa is

initWithBitmapDataPlanes:pixelsWide:pixelsHigh:bitsPerSample:samplesPerPixel:hasAlpha:isPlanar:colorSpaceName:bitmapFormat:bytesPerRow:bitsPerPixel:

It’s certainly not the cause of your problem, but it’s recommended to consider the Cocoa naming conventions.
Method names should start with a lowercase character, class names with an uppercase character