Getting text from a window text field
Hi all,
I have a carbon app, with a window that is created from a NIB. The window has some text fields.
Currently, to get a text string that has been entered in a text field, I'm calling
GetControlByID()
GetControlData()
and then I'm doing this
const char *theText = CFStringGetCStringPtr(ref, CFStringGetSystemEncoding());
However, I am finding that this returns NULL in the case of a Japanese user of my application.
Can anyone shed some light on how I should really handle this?
I've looked at the CFString documentation, but it's somewhat daunting in terms of working out what actual conversions I should be using (or shouldn't be!).
thanks!
I have a carbon app, with a window that is created from a NIB. The window has some text fields.
Currently, to get a text string that has been entered in a text field, I'm calling
GetControlByID()
GetControlData()
and then I'm doing this
const char *theText = CFStringGetCStringPtr(ref, CFStringGetSystemEncoding());
However, I am finding that this returns NULL in the case of a Japanese user of my application.
Can anyone shed some light on how I should really handle this?
I've looked at the CFString documentation, but it's somewhat daunting in terms of working out what actual conversions I should be using (or shouldn't be!).
thanks!
I'm sure the system encoding is always MacRoman, which only covers western europe at best.
UTF-8 is the only 8-bit encoding it's ever safe to use.
In general, you should be using CFStrings throughout your application. Why do you need to convert to an 8-bit encoding?
UTF-8 is the only 8-bit encoding it's ever safe to use.
In general, you should be using CFStrings throughout your application. Why do you need to convert to an 8-bit encoding?
Well, this is what I'm trying to work out. There are two parts here. A server-based name verification system, and an application-specific part. I want to do some operations on the inputted text (customer name) to verify it against serial numbers that are generated from a system that does not support CFStrings.
How should I be going about this?
thanks.
How should I be going about this?
thanks.
then it's a question of how that other system handles text...
The other system just handles 8bit chars, AFAIK. In any case, what should I be doing on the Mac end?
like I said, it depends what the other end does. There's no such thing as "an 8-bit char", it's always in a particular encoding. You need to find out what that encoding is and how the system deals with characters that aren't representable in that encoding. Then you need to make your application do the same, probably either by preventing invalid input into your text field, or by transforming invalid input into the form the other system will accept it in. Either way, remember to give the user live feedback
I appreciate the help, but I'm still confused as to what is really needed here.
The customer is sent an email with registration details to be entered into the application.
e.g. Customer Name: "Fred Brown"
now, this name is presented to the customer, as presented here. (e.g. Roman characters)
The customer then types "Fred Brown" into the registration window. My Japanese customer is doing this, but CFStringGetCStringPtr() is returning NULL.
I hope that helps a bit?
thanks.
The customer is sent an email with registration details to be entered into the application.
e.g. Customer Name: "Fred Brown"
now, this name is presented to the customer, as presented here. (e.g. Roman characters)
The customer then types "Fred Brown" into the registration window. My Japanese customer is doing this, but CFStringGetCStringPtr() is returning NULL.
I hope that helps a bit?
thanks.
It might just be a matter of using CFStringEncodingMacRoman or CFStringEncodingASCII or whatever is appropriate rather than the system encoding, which is probably a multibyte encoding on Japanese systems.
Either way, you're probably not going to be able to get the C string pointer. Read the docs, that function is a performance optimization for the cases where the string is actually stored in that form.
Either way, you're probably not going to be able to get the C string pointer. Read the docs, that function is a performance optimization for the cases where the string is actually stored in that form.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Read a text file line by line? | jdunehew | 6 | 9,211 |
Dec 29, 2011 11:54 AM Last Post: Blacktiger |
|
| Smart Field Initializers | IckyThump | 6 | 2,931 |
Aug 11, 2009 03:58 PM Last Post: IckyThump |
|
| im creating a text base game site | DEMILUST | 0 | 2,116 |
Dec 15, 2008 03:07 PM Last Post: DEMILUST |
|
| Help for drawing text with Quartz | Terrydil | 2 | 3,806 |
Oct 21, 2007 06:59 PM Last Post: Terrydil |
|
| OH GAWD! Text parsing in cocoa?!?!? | hypnotx | 6 | 3,956 |
Jul 5, 2007 12:57 PM Last Post: SethWillits |
|

