Pascal Dynamic Libraries: More Than You Want To Know

Part 2: Passing Pointers and Strings


The ndfd example library

The example library code for Part 2 is finished, but the notes on passing pointers and strings are still under construction. The notes for Part 3: GIS for Pascal are available, though, and use part 2's example library.

So, if you want to use Part 2's ndfd library with Part 3's GIS examples, just run the supplied script (.sh) or batch (.bat) files in the ndfd subfolder of Part 3's p4g.zip to build the binaries that you'll need for the examples.

Compiling the ndfd library

The ndfd library calls the National Digital Forecast Database (NDFD) REST service to retrieve weather forecast data, so you'll need an HTTP client to compile the library. Unfortunately, Free Pascal's HTTP client does not work with NDFD's new HTTPS protocol, so you'll need to use another client, such as Indy, Synapse or, on Mac, the Foundation-based NS client (nsunits-src.zip).

Run the appropriate script and specify the HTTP client to use and the location of its files. Use one of the following defines on the script command line:

For example, to compile the library on a Mac, using the Foundation-based HTTP client, enter something like this (adjust the path as needed):

./comp-fpc-lib.sh -dUseNSHttpClient -Fu~/Tools/nsunits-src

Another example, to compile the library on Windows, using Indy, enter something like this (adjust the path as needed):

comp-fpc-lib.bat -dUseIndyHttpClient -FuC:\Tools\indy

Note that Indy and Synapse require the OpenSSL libraries to communicate with sites that use the HTTPS protocol. On Mac and Linux, these libraries are already installed, but on Windows you'll need to obtain them yourself and place them somewhere on the path on in the same directory as the NDFD library. You can download them from here.

Using the NDFD SOAP service (optional)

You can also use NDFD's SOAP service if you're interested in that. To compile the library, you'll need to specify the -dUseNdfdSoap switch and you'll need the Web Service Toolkit (WST).

You do have WST, right? If not, change to a folder where you want to put the WST source files and check them out like this:

svn co https://svn.code.sf.net/p/lazarus-ccr/svn/wst/trunk .
Documentation is here: http://wiki.freepascal.org/Web_Service_Toolkit

For example, to compile the library on Mac or Linux, using Synapse and the NDFD SOAP service, enter something like this:

./comp-fpc-lib.sh -dUseSynapseHttpClient -Fu~/Tools/synapse-trunk -dUseNdfdSoap -Fu~/Tools/WST

Using the ndfd library

There are some other scripts or batch files you can run when you're ready to use the ndfd library.

For example, to use the ndfd library with Python, compile the Python extension module using one or more of these:

comp-fpc-pymod.sh
comp-fpc-pymod3.sh
comp-fpc-pymod.bat
NdfdLib.pas is the Pascal wrapper class for the library. To use it with Lazarus, compile this Lazarus package:

lazbuild ndfd_pkg.lpk
To compile the .NET/Mono assembly that wraps the ndfd library, run one of these:

comp-cs-interop.sh
comp-cs-interop.bat
On Mac, you may prefer to work with the library as a framework. Once you've compiled the library, you can run a supplied script to create a framework for it:

create-framework.sh
To use the NDFD.framework with Lazarus, compile this package:

lazbuild ndfd_framework_pkg.lpk

Copyright 2015 by Phil Hess.

macpgmr (at) icloud (dot) com

First posted March 15, 2015; last edited July 17, 2017.