TCL OOPs Intro
Volume Number: 6
Issue Number: 9
Column Tag: C Forum
TCL OOPs Introduction 
By Mark B. Kauffman, Tucson, AZ
Note: Source code files accompanying article are located on MacTech CD-ROM orsource code disks.
An Introduction to Object-Oriented Programming With THINK C
[Mark Kauffman is currently employed at Burr-Brown Research Corp. in
Tucson, Arizona, designing and programming test equipment. He has been
programming micro-computers for 14 years. He has owned and programmed a
Macintosh since its introduction in 1984.]
This article is written for C programmers who are interested in learning the
object-oriented programming concepts available in THINK C. It includes example code
that defines a class of shapes and then draws some shapes in a window on the Macintosh
screen. This example is designed to be used with the Starter project that comes with
the THINK C 4.0 compiler. By reading this article and trying out the example code, you
will gain a clear understanding of the object-oriented concepts of class, inheritance,
objects, polymorphism and messages.
Create a New Project and Add the Example Code
Create a working copy of the Starter Folder included in the THINK C compiler as
follows: Copy the Starter folder, change the new folder name from “Copy of Starter
Folder” to “Object1 Folder”. Open the Object1 Folder and change the word “Starter”
to “Object1” in all of the file names that contain the word “Starter”. Now open the
Object1 project (Object1.π) and use the THINK C Find... command in the Search menu
to find and replace all occurrences of “Starter” with “Object1” in all of the files used
by the project. This procedure allows you to preserve the original Starter Folder for
later use in creating new projects.
Use the THINK C file editor to create and type in the three source file listings.
Name the files CShapes.c, CShapes.h and DrawMyStuff.c. Add CShapes.c and
DrawMyStuff.c to the Object1 project using the Add... command under the Source menu.
Open the source code file CObject1Pane.c and find the Draw method...
void CObject1Pane::Draw(Rect *area)
Underneath the line,
add the following line...
DrawMyStuff();
When you run the project you should see some circles, rectangles and a line
drawn in a window. One of the rectangles should be missing a line across the top and
one of the “circles” will be oval shaped. See figure 1.