Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
Hello, I have the following problem. I have made this window:
attachment.php

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?
 

Attachments

  • Picture 1.png
    Picture 1.png
    15.2 KB · Views: 260

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
yes, because it was my mistake. no strange programming workarounds here.
 

iSee

macrumors 68040
Oct 25, 2004
3,540
272
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.
 

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
kainjow said:
Soulstorm: I'm curious, why are you learning Carbon?
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?
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
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
 

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
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?
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
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...
 

Soulstorm

macrumors 68000
Original poster
Feb 1, 2005
1,887
1
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?
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
Soulstorm said:
I
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?
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.