Little JOBS and Big JOBS
Using Delphi 2.0 to control J 3.02 automation
server OBjects
John D. Baker
J96 User Conference
OLE automation is a
Windows operating system service that allows one application to automate or
control the exposed objects of another application. OLE automation makes it
possible for one application to efficiently use the facilities of others. This
talk will show how Delphi 2.0 applications can use J's EXE and DLL automation
servers.
Delphi 2.0 is a 32 bit Object Pascal client/server oriented
visual programming environment that has attracted a large and loyal following.
Many factors have contributed to Delphi's success. I would single out the
following:
- Delphi's high speed optimizing Object Pascal compiler. Competing products
like Visual Basic and PowerBuilder have yet to release compilers. (Power
Builder 5.0 will include a native code compiler when it's released. There has
been no official word on a Visual Basic compiler yet.)
- The Object Pascal language. There has long been a need for a serious
compiled Windows programming tool that is not based on C++.
- The intelligent use of easily customized visual components.
- A productive integrated development environment.
- Integrated support for a wide variety of local and SQL database systems.
- The ability to build OLE automation servers and controllers.
- The limitations of competing database development tools.(I was attracted
to Delphi when I read about the massive runtime support files required to run
new FoxPro applications.)
Delphi has many strengths but array
processing is not one of them. Object Pascal has fixed the outrageous
limitations imposed on arrays by early versions
of Pascal. For example in
Object Pascal:
- An entire array can be passed as argument.
- Facilities exist to determine the shape of an array at runtime.
- Variant arrays can include other arrays as elements.
- Strings, (indexed like arrays), can now be larger than 256 characters.
(Delphi 2.0 strings can be as large as 2 gigabytes.)
Be still my
beating heart!
What is Delphi still missing?
- Empty arrays! The most fundamental and least understood array concept.
- Complex numbers. You can define a complex type and easily declare complex
arrays in Delphi. Unfortunately you are left with the tiny matter of
providing all the standard and transcendental complex functions.
- Common matrix processing facilities, matrix product, matrix inverse,
determinants, least squares and polynomial evaluation.
- Array oriented search and membership functions.
- A coherent boxed array model!
J programmers could go on beating up
on Delphi arrays but that's not the way to
win friends and influence people.
Besides, J has its own limitations and weaknesses.
The glory of OLE
automation is that it offers programmers an easy way to combine the strengths of
different programming tools.
Together, Delphi and J, can easily do things
that would require mountains of code in either one
Example JOBS
(J automation OBjectS)
There are many ways to use J
automation servers from Delphi but most applications will be:
A Little JOB is a J automation server that contains few,
if any, J words. A little JOB is basically a super array calculator. This is the
way most Delphi programmers will use J.
A Big JOB is an automation server
loaded with a large J system. J programmers can use Delphi to give their big
JOBS a polished state-of-the-art Windows interface.
The remainder of this
presentation will demonstrate examples of little and big JOBS.
Little JOB #1: Prime Factors
In this example I will program, from
scratch, a simple Delphi/OLE/J application that computes the prime factors of
the first 1000 integers and displays the results in a Delphi grid.
Little JOB #2: Sunrise and Sunset Times
This example will demonstrate
the automation of a nontrivial, but easily understood, J array algorithm that
computes the time of sunrise and sunset for any point on Earth.
Little JOB #3: Storing J Words In Delphi Databases
I will demonstrate a
Delphi application that controls a J workspace. By clicking on a few controls
entire J workspaces can be saved in Delphi
tables. A few more clicks will
suffice to generate J scripts, on the fly, from database entries.
A Big JOB: Running a J macro-processor from Delphi
If time permits I
will show how Delphi can control the execution of a large J application.
Finally: Caveats, Limitations and Gotcha's
New technologies are born
with congenital defects. OLE automation, as it is currently supported by Delphi
and J, has a few rough edges.
- Delphi OLE calls do not yield J return codes. This is definitely a problem
with Delphi since Visual Basic properly handles J return codes.
- Delphi can easily read nested arrays from J but going the other way is
difficult.(I haven't figured it out yet.) There are no problems with sending
flat arrays of type double or floating. Character arrays require a little
voodoo to handle the varbyte representation.
- J is currently an asymmetric OLE automation server. It excels as a server
but is a poor client or controller.
- OLE automation requires a lot of RAM to be effective. A 16 megabyte
machine is marginal for Delphi/OLE/J combinations.