Getting text from a window text field

Member
Posts: 31
Joined: 2004.09
Post: #1
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!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
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?
Quote this message in a reply
Member
Posts: 31
Joined: 2004.09
Post: #3
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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
then it's a question of how that other system handles text...
Quote this message in a reply
Member
Posts: 31
Joined: 2004.09
Post: #5
The other system just handles 8bit chars, AFAIK. In any case, what should I be doing on the Mac end?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
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 Smile
Quote this message in a reply
Member
Posts: 31
Joined: 2004.09
Post: #7
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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #8
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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Read a text file line by line? jdunehew 6 11,549 Dec 29, 2011 11:54 AM
Last Post: Blacktiger
  Smart Field Initializers IckyThump 6 3,408 Aug 11, 2009 03:58 PM
Last Post: IckyThump
  im creating a text base game site DEMILUST 0 2,342 Dec 15, 2008 03:07 PM
Last Post: DEMILUST
  Help for drawing text with Quartz Terrydil 2 4,170 Oct 21, 2007 06:59 PM
Last Post: Terrydil
  OH GAWD! Text parsing in cocoa?!?!? hypnotx 6 4,438 Jul 5, 2007 12:57 PM
Last Post: SethWillits