Tuesday, February 05, 2013


I was reading Paul Graham's book "Hackers and painters" last week; whilst the early chapters were interesting, the later chapters became more dogmatic. Probably I work in an environment which is beneath contempt - Windows/Delphi/Firebird - which explains why my mind is closed to the beautiful concepts espoused by Mr Graham.

On Friday, during my weekly meeting with the Occupational Psychologist (OP), we were talking about priorities and she said that her immediate priority was to deal with salaries (the meeting took place on Feb 1). Her current method of operation is to go into the screen in the management program which displays all the meetings, projects, expenses and work hours recorded for all the therapists, create a Word file of this data (the program does this automatically), check the data in the file, make corrections and then send individual Word files to each of the therapists, fishing for comments.

Suddenly a light bulb lit in my brain. My immediate reference was to the chapter in Graham's book about leverage; the OP didn't seem to be too familiar with the concept. I explained that I had come across the term primarily in my financial studies, using the example of the Israeli 'tycoon'  Ilan Ben Dov, who borrowed money at an interest rate of (say) 5% in order to buy a controlling share in the national telephone company, Bezek, which should have returned money at (say) 8%. Unfortunately, the bottom fell out of the telecommunications market about a year ago and as a result, his investment was returning only (say) 4%.

What is the relevance here? I spent a few illuminating weeks (that's a good euphemism) learning how to send Hebrew emails with attachments; we could leverage that knowledge so that the program could send those individual Word files automatically to the therapists!

I would like to say that the implementation of this idea was simple but it turned out to be more complicated than I had expected. The existing implementation leaves the Word file open on the screen (in Word, obviously), waiting for the user to do something with it (like posting the file), whereas I needed a file saved in the file system which I could then use as an attachment. Eventually I solved all the problems, thus allowing those Word files to be sent automatically.

But knowing the OP, I was sure that she would want to keep a record, not only of to whom such files were sent but also the contents of the files. As I wasn't prepared to keep the Word files, let alone store them in the database, some thinking was required. I'm not too sure where the idea came from, but it occurred to me that I could create the data as HTML and save that in the database. A first attempt took the Word file and saved it as HTML (thus moving from a proprietary format to an open one); this caused the resulting file to be twice the size of the original file (expanding a 20KB file to 40KB, if not more)! Word creates extremely verbose HTML.

It then became clear that my program would have to create its own HTML code and then either display it on the screen (which required saving it to file first) or inserting it into the HTML text (that sounds like an oxymoron) of an email. It took a few hours to create the initial HTML report, but I am pleased to say that the Delphi code which does this is much cleaner than the corresponding code needed to create the Word version, and the resulting HTML file's size is only 2KB as opposed to 20KB (this was after tuning the HTML code itself)!

After a few more hours of fiddling around (in which I discovered that my demo version was freeing a stringlist more often than the stringlist was created, thus causing memory violations), I finally achieved a professional version which creates the data, displays it and optionally sends it by email (I used a multi-select dbgrid for this). If an email is sent, an entry is made in the appropriate table in the database and the HTML code is saved. A few more minutes work, and this saved HTML could be retrieved from the database and displayed. This will be useful if we want to see what were the contents of the email sent to therapist A on 01/03/13. For this, I used leverage again: there already exists in the program a form which contains an HTML browser, so I didn't have to create yet another browser form in the program.

The next stage in the leverage chain is to take my new found knowledge of HTML tables and use it in a different program. I wrote one called 'Inspector', which as its name suggests, inspects files, specifically those created by the OP's flagship exam. The current display is ok but could be improved, and it occurred to me that the visual improvement would come about by using HTML to display whatever has to be displayed instead of a list view.

No comments: