Problem with Carbon Input Fields

Discussion in 'Mac Programming' started by Soulstorm, Apr 9, 2006.

  1. macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #1
    Hello, I have the following problem. I have made this window:
    [​IMG]
    which is self-explanatory. All command event handlers are handled properly.

    There is one problem though. Below is the code that handles the conversion to uppercase:
    Code:
    pascal void MyCommandHandler(WindowRef window){
    	cout << "handler\n";
    	ControlHandle stringInTextEdit;
    	ControlHandle stringOutTextEdit;
    	
    	ControlID stringInControlID = {kControlSignature, kStringInControlID};
    	ControlID stringOutControlID = {kControlSignature, kStringOutControlID};
    	
    	CFMutableStringRef theString;
    	
    	GetControlByID(window, &stringInControlID, &stringInTextEdit);
    	GetControlByID(window, &stringOutControlID, &stringOutTextEdit);
    	
    	GetControlData(stringInTextEdit,
    				   kControlEntireControl,
    				   kControlEditTextCFStringTag,
    				   sizeof(CFStringRef),
    				   &theString,
    				   NULL);
    	
    	CFStringUppercase(theString,NULL);
    
    	SetControlData(stringOutTextEdit,
    				   kControlEntireControl,
    				   kControlEditTextCFStringTag,
    				   sizeof(CFStringRef),
    				   &theString);
    	DrawOneControl(stringOutTextEdit);
    
    	cout << theString;
    }
    the problem is that I don't see any letters drawn on the second text field! What is my fault?
     

    Attached Files:

  2. thread starter macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #2
    Problem Solved Moderators Please Remove This Thread
     
  3. Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #3
    You sure that someone else new won't need the answer some day?
     
  4. thread starter macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #4
    yes, because it was my mistake. no strange programming workarounds here.
     
  5. macrumors 68040

    iSee

    Joined:
    Oct 25, 2004
    #5
    Hmmm, just 7 minutes between the OP and self-found fix.

    Actually, having working with teams of programmers for a long time, it is interesting how often this happens: A fellow programmer stuck on something, sometimes for hours, comes to ask for help. Just by explaining the situation and posing the question they suddenly realize what the solution is. :) Sometimes they don't even get half way through the explanation before they say, "Oh wait! never mind, I've got it." and walk away.

    Orgainizing your thoughts in order to explain something to someone else is an effective analytical approach.
     
  6. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    Soulstorm: I'm curious, why are you learning Carbon?
     
  7. thread starter macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #7
    I've been asking myself the same question over and over again.

    The short answer is because I want to have some of my C++ programs use GUI. And I don't know Obj-C, so Carbon is one-way for me.

    But so far, all I see is that carbon is really inexplicably difficult. Perhaps I should learn Obj-C and move to Cocoa? Note that I intend to keep my programs Mac-Oriented, so, portability is not my primary concern (if I move to Windows or Linux, I will learn another API, I am 20 years old and I have all my life ahead of me to do so...).

    From your question it seems you would advise me against using carbon...

    What is your opinion?
     
  8. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #8
    If you're simply wanting to put a GUI to your C++ programs, and you don't care about Windows or Linux, then Cocoa is the way to go.

    Since you're learning Carbon, you mine as well put your efforts into learning Cocoa.

    Here's the Objective-C/Cocoa equivalent of what you're trying to do:

    Code:
    - (IBAction)convertToUppercase:(id)sender
    {
    	[textBox2 setStringValue:[[textBox1 stringValue] lowercaseString]];
    }
    That's it. The main thing about Objective-C/Cocoa is learning Objective-C's syntax, but if you know C/C++, it'll take you about a days worth of learning. Then, it's just a matter of learning the APIs.

    There's tons of info about Cocoa over at http://www.cocoadev.com also
     
  9. thread starter macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #9
    Code:
    - (IBAction)convertToUppercase:(id)sender
    {
    	[textBox2 setStringValue:[[textBox1 stringValue] lowercaseString]];
    }
    damn. I am really jealous now. I should learn Obj-C and then move to cocoa... I'm a bit afraid of learning a new language, but since I have a background in OOP with C++, it shouldn't be a problem...

    I will go and buy a book tomorrow to learn Obj-C. Any good recommendations?
     
  10. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #10
  11. Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #11
    Actually the line should be
    Code:
    [textBox2 setStringValue:[[textBox1 stringValue] uppercaseString]];
    
    if you want to convert to upper case.;)

    Seriously objective-C is a pretty easy language. It's miles easier to learn than C++. The hard part is remembering the Cocoa API but then again you're spending a lot of time learning the carbon API so the work learning the Cocoa version should be comparable.

    Can I also add Steve Kochan's book to the list. It's more an Objective-C book than a cocoa book but covers the language well. There's also this primer on the Apple site although it's a bit dry...
     
  12. thread starter macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #12
    I ordered those books from amazon.com.
    But when I try to speak to any reseller here in Greece, they don't even know what Obj-C is. They're like "Are you sure there is such a language?".

    Is there Obj-C on the PC (I suppose there is)? Is it extensively used, or it is just the most widely used language on the Mac?
     
  13. Guest

    caveman_uk

    Joined:
    Feb 17, 2003
    Location:
    Hitchin, Herts, UK
    #13
    It's not widely used on PC (if at all) and is most extensively used on the mac but it's not a 'closed' language as support for it is built into the GNU gcc compiler. You can compile objective-C code on any system that can use the gcc compiler. You can also use the GNUstep libraries which are an open source version of the NeXTStep libraries which ultimately became Cocoa (http://www.gnustep.org/). If you wanted you could use GNUStep and the gcc compiler to create cross platform code.
     

Share This Page