Science makes it known,
Engineering makes it work,
Art makes it beautiful.
|
|
D .dll Calling Pascal .dll - Pascal Files
Parsing Command Line Parameters Processing
The Pascal backend of
D .dll Calling Free Pascal .dll - D Files.
In both Lazarus and Object Pascal the command line parameters are
available via a call to function ParamStr (index), which returns
the indexth
command line parameter as a string (it can be
returned to a char array variable). ParamStr (0) = the program's
name. In D, the entire command
line parameters are accessible by a single char*.
The Pascal .dll (allazrs.dll) consists of one Object Pascal file, one
Lazarus unit, and LCL units. The procedures and functions in
allazrs.dll have
been successfully called by both a Free Pascal Windows program and a
D .dll.
Requires both Free Pascal
(for ALlazrs.pas) and
Lazarus
(for NumRecGlbl.pas and Interfaces.ppu).
Pascal Files:
-
ALlazrs.pas -
originally developed for software reuse of user written unit
NumRecGlbl's command line parameter (ParamStr (i)
and ParamCount) processing, as well as mapping a
1 dimensional array to
a 2 dimensional matrix, in a Free Pascal
Windows program.
In this application LIBRARY ALlazrs
procedure DCMDLINE (...) is called by D module
CmdLine procedure callDCMDLINE (...) as
part of D Windows program command line parameter processing.
allazrs.dll - ALlazrs.pas dynamic link library, compiled with
a modified
fpcdll.bat
(see below)
allazrs.lib - allazrs.dll
|
![ALlazrs.pas source code screen shot](al1.gif) |
import library (not used for Pascal applications, required for D
applications - used when linking the D .dll in the D module's
pragma (lib, "ALlazrs.lib") statement), built using Digital Mars
implib utility (file bup.zip).
units Windows and LCLType
(used by Interfaces) both define a
Window Handle type HWnd. Windows.HWnd is
compatible with both D
and Object Pascal.
-
Interfaces.ppu - Lazarus Component Library (LCL) component
unit description file; required for useing Lazarus unit
NumRecGlbl in
Object Pascal LIBRARY ALlazrs.
(In LIBRARY ALlazrs, recommend
explicitly defining HWnd handles as either type
Windows.HWnd
or type LCLType.HWnd)
-
NumRecGlbl.pas -
Numerical Recipes1
secondary unit used in Lazarus project
Lazarus, Free Pascal, Silverfrost FTN95, and Numerical Recipes;
contains command line parameter processing, file validation (when
file name included in command line parameters) using the Dos
unit, and indices mapping for a 1 dimensional array
to/from a TStringGrid, adapted for use via allazrs.dll in a
Free Pascal Windows application.
numrecglbl.ppu - NumRecGlbl.pas unit description file.
genetyp.inc2
- include file developed from major rewrite of
Dawkins8 Biomorphs2
(Free Pascal dawkins8.dll callable from both
Pascal and D programs); contains useful CONSTant and
TYPE declarations
nrtyp.inc
- Numerical Recipes include file
|
![NumRecGlbl.pas screen shot from Lazarus Source Editor](nrg.gif) |
-
hwndio.dll - used in Free Pascal
Windows programs, not used in
D .dll Calling Free Pascal .dll - D Files;
hwndio.pas
dynamic link library;
collection of
Free Pascal general purpose functions for Windows
Edit Controls I/O, field tabbing.
DCMDLINE (...)
Procedure name must be upper case to be D callable.
Constants, variable iErr, functions
CurParamSwitch (...) and
cmdLnFname (...) defined in Lazarus unit
NumRecGlbl.
Call LIBRARY ALlazrs procedure DCMDLINE (...)
to search for/process input file parameter or artificial life related
arguments.
D module CmdLine procedure prcCmdLine (...)
extracts a command line parameter from the char* command line
parameters list passed to the D main program by Windows, and saves it
in a character array. (prcCmdLine (...)
is primarilarly used for artificial life/simulated annealing
applications.)
prcCmdLine (...) calls
D module CmdLine procedure callDCMDLINE (...)
(may call other procedures as well).
callDCMDLINE (...) calls
DCMDLINE (...) (examining the source code may help
to explain why done this way)
|
![ALlazrs.pas screen shot showing DCMDLINE (...)](al3.gif) |
Pascal Compiling/Linking:
-
In addition to the -WR switch, fpcdll.bat will also need the
following switches:
-FuD:\lazarus\lcl\units\i386-win32
-FuD:\lazarus\lcl\units\i386-win32\win32
-FuD:\lazarus\components\lazutils\lib\i386-win32
(the above values reflect my Lazarus installation,
which is on the D: drive, \lazarus directory; be sure to adjust the
additional switches to
reflect your installation)
To compile ALlazrs.pas and its associated files into allazrs.dll,
open a D2 32-bit Command Prompt and type:
fpcdll ALlazrs
(Can safely leave above additional switches in
fpcdll.bat if the Object Pascal
|
![Command Prompt - building allazrs.dll, allazrs.lib](al2.gif) |
Library does not need them; or
can write another batch file, lcldll.bat for example, which
passes the above switches along with the
source file name to fpcdll.bat.)
-
To build allazrs.lib, in the same D2 32-bit Command Prompt, type:
implib allazrs.lib allazrs.dll
1. Press, William H., Brian P. Flannery, Saul A Teukolsky,
and William T. Vetterling (1986). Numerical Recipes: The Art of Scientific
Computing.
New York:Press Syndicate of the University of Cambridge.
2. Rietman, Edward (1994). Genesis Redux: Experiments Creating Artificial
Life. Windcrest (McGraw-Hill).
The original Dawkins8 source consisted of one unit and one MS-DOS main program
(without any modularity whatsoever). Broke that down into two
Windows
callable .dll's (genecode.dll and dawkins8.dll) and one
include file. The main .dll is now very modular.
|