Radsoft
 About | Buy | News | Products | Rants | Search | Security
Home » Resources » Red Hat Diaries

Red Hat Diaries/0043

I Did It

It was a matter of not using books, of seeing what was in my head. And it took a long time. It's OO and it's Obj_C and it's NextStep, and I only picked on old Maury with the SpamStopper, but after a night of bad whisky it was mine.

It's 18,040 on disk, so it's not close to the Windows version at 4,608 bytes, but on the other hand it's even farther from Maury's 990KB for this trivial app.

It took a lot of work and black art stuff. Converting strings from the default NS Unicode format to ordinary ASCII strings, then parsing, processing and sending it all back again in the original format, but it works. Enhancements come in version 2!

The most difficult part of this is the interface. This is handled by the Interface Builder tool, and it's almost impossible to see clearly what has been done and what has not been done, as well as figuring out how to undo something once it's done. This is not code, this is not text, this is very sophisticated gobbledegook, but it's almost impossible to get at any better. -If- it works, it's a boon, as so many things are actually provided at build time and the code needed to run even complex applications becomes minimal and sometimes almost trivial.

In the graphic below you will note a pushbutton with the text 'Convert'. It's when this button is pushed that the magic takes place. But the app does not need to establish any message pump, and it does not need a window procedure to flag all incoming messages to the window. Nope, already in the Interface Builder you literally 'connect' the button with a 'method' in your code - and you do this not by typing in any code to do it, but by -dragging the mouse-. And then, automatically, at run time, when the button is clicked, your method is called. And you of course know exactly what to do: get the text from each of the first two fields and put the results in the third one.

And that's it. The code has a -single function- - a 'method'- - to handle the event that the Convert button is pushed. That's it. -There is no other code whatsoever.- Even the About box is completely gratis. You supply the strings and it displays the box.

All you have to do is learn how to connect objects in the window with methods. That's it. You have to connect so-called 'outlets' too. You make a class declaration with a number of 'id' pointers which point to the first text field, the second text field, and the third text field. (You do not need a pointer to the button, you don't do anything with it.) But here again is the trick: You don't have to seek out these text fields at runtime; they are already connected for you by Interface Builder - they're already built into the code at build time.

Again, if it works, and if you don't screw up, it's bloody brilliant. You just drag your mouse all over the place. If you screw up, you can panic easily - I know I can, for I did last night, and it wasn't fun. And for the moment I will have to start all over again, because this stuff is not text and you can't compare one file with another and/or, what I know, just copy in one over another. So you have to be careful - at least until you learn how to undo any eventual mistakes.

But given that that is possible - whoa, for this is the streamlined jet version of GUI programming.

Click here »

About | Buy | News | Products | Rants | Search | Security
Copyright © Radsoft. All rights reserved.