` Printed Icetips Article

Icetips Article



OOP: Better OOP part 3
2003-04-12 -- Dan Pressnell
 
Newsgroups: comp.lang.clarion,topspeed.topic.oop

March 5, 2006:
Note that the code is now available at:

http://www.icetips.com/downloadfile.php?FileID=59

The highest level of reusibility of an object (CLASS) would be if it were
contained in a DLL.  Here are the basics to get the compiler and linker to
do their job correctly, both for the DLL that contains the class executable
code and an exe or another dll that uses the class.

Let's make some assumptions here.  You will create a class whose code will
be in a DLL file, and that class may refer to global data or procedures in
that DLL app.

First, you must declare the class with some extra attributes, like this.
Assume the name of your dll APP is MyApp

MyClassType    class, type, module('myclasses1.clw'), link('myclasses1.clw',
myapp_linkmode), dll(myapp_dllmode)
... etc.

The module attribute says "Here is where the executable code for my class
is."

The link attribute says "Compile myclasses1.clw if the equate myapp_linkmode
is true, and link it into the exe or dll I am currently creating.  If
myapp_linkmode is false, don't compile it--don't even look for it--and don't
link it."

The dll attribute says "This class's executable code is contained in an
external DLL, not in MyApp."

For the app that you intend to include your class code into, you should put
this in your global embeds:

myapp_linkmode    equate(1)
myapp_dllmode      equate(0)
    include('myclasses1.inc'), once

For any other app, DLL or EXE, that uses this class, you would put this in
your global embeds:

myapp_linkmode    equate(0)
myapp_dllmode      equate(1)
    include('myclasses1.inc'), once

... and in your project settings, add the dll that contains the code to the
external libraries.

(You can also use project settings to set these flags, like this...

myapp_linkmode=>1
myapp_dllmode=>0

... but under nearly all situations with apps (less often with hand coded
projects) using the equates in the global embeds will work fine.

Another consideration is what to put for the MEMBER statement in the class's
executable code module.

Because we have assumed that you are creating a class that must have access
to the global data of your DLL app, you should put this:

  MEMBER('MyApp')

There are cases where you should not specify MEMBER() but those are
specialized cases where you are usually developing some tool that doesn't
have a need to access specific application data or procedures.

Now the bad news:

Because you need one INC file and one CLW file for this to work, the
application generator is not going to give you much help.  You'll have to
use external source files that are outside the application tree environment.
Also, you now have an issue of putting the correct information into the EXP
file so the linker will "export" the class and its methods to make them
visible to other apps that will use the class.

The good news is that I've developed a template that will allow you to do
this within the app procedure tree, and will create, at generation time, the
inc and clw files for you.  It can also parse the INC file and add the
needed entries to the Export section.

This template allows you to keep your class declarations and code in the app
procedure tree like everything else.

You can get the template along with a sample app at
http://toolwares.com/oop_sample.ZIP .  Put the tpl file in your template
registry, and open the oop.app file (c55 required) to see how it's used.
The app file has no dictionary specified, and uses the baseball.mdb (Access
database) that I used in my Better SQL series, using one of the techniques
described there.

I'll discuss the sample application later.

Note:  Using the template, if you get compile errors, you will not be able
to edit them in place (changes won't be saved).  I don't think that can be
fixed.

Dan



Printed November 23, 2024, 2:21 am
This article has been viewed/printed 35400 times.
Google search has resulted in 42 hits on this article since January 25, 2004.