Dev-Picayune

picayune: of little value or importance

Archive for February, 2006

Some New Short Articles (Mostly Clarion-Related)

I have posted two articles to my articles section here. One of them is on a very rough Clarion export template and the other deals with more of the specifics about calling Clarion from Python that I had originally mentioned in my past entry Getting Jiggy with Clarion and Python.

Technorati Tags: , , , ,

No comments

Getting Jiggy with Clarion and Python

My current job involves attempting to maintain and enhance a huge Clarion 5.0 POS application. As a now former Clarion expert (it had been a couple of years since I had done much with it), I decided to see what I could still do. One of the latest requests was to have a method of exporting some of the native TopSpeed database tables (TopSpeed is a proprietary database file type that the Clarion folks (aka SoftVelocity) offer). Since we’re not planning on buying hundreds of copies of their overpriced ODBC driver, I needed a way to export some of those files from within Clarion (since it already has the TopSpeed->Clarion driver in it).

Using Clarion’s Template language, I created a procedure template that builds a fairly straightforward conversion procedure. I then used that template to generate procedures for each of the files that I wanted to be able to export. Then I created a controller procedure that would call the appropriate procedure based on the passed in parameters. Initially, I was going to try to create a command-line program in Clarion using some of Paul Attryde’s tips (Paul is another former JDA person like myself). But looking at what’s going on, I wasn’t sure that it would work the way I wanted, so then I began to search for a way to call Clarion from Python.

After poking around a little, I found the ctypes module would do exactly what I needed and that is interface to a Windows .DLL. My overly simple (no exception handling) example script looks like this:

 import sys from ctypes import *   def exportFile(tableName,outputFileName):     wd = windll.LoadLibrary('exportfi.dll')     cTableName = create_string_buffer(tableName,10)     cOutputFileName = create_string_buffer(outputFileName,255)     expcon = wd.EXPORTCONTROLLER     expcon.restype = c_byte     return expcon(cTableName,cOutputFileName)  if __name__ == '__main__':     if len(sys.argv) != 3:         print "usage: exportfi tablename exportfilename"     else:         exportFile(sys.argv[1],sys.argv[2])  

The end result is that it is able to call my Clarion created .DLL just fine, which gives me a command-line utility for exporting files. And since the .DLL is dynamically linked, I can update the Clarion .DLL with new files to export at any time without having to upgrade the Python program.

Technorati Tags: , , , , ,

No comments