Sunday, July 25, 2010

The in-basket 4

After walking around for a few days with my head in sky, playing with AI programs, I thought that it was time to return to Earth and improve the in-basket exam. At the moment, the exam is unique in that it accesses a database in order to find its data, whereas all the other exams which I have written, including the aptitude exam, have their data compiled into a resource file which is attached to the executable exam. Could I do the same with the in-basket?

At first, I thought that this would be not be possible, as there are all kinds of gotchas in this exam - rich text has to be displayed, replies have to be referenced, etc. But after a while, I realised that it definitely would be possible to convert the exam to reference a resource file and not a database. The rich text was actually simple to solve: the 'administrator' program saves each rich text entry in the database as an rtf file, and these are then loaded into the rc (resource source) file. Storing the people referenced in the exam turned out to be very simple: the program adds 10,000 to each person's id (so as not to clash with message ids), and in the stringtable are stored as separate strings the person's name, job and comments. The messages were also fairly easy to store.

Rewriting the exam to use a resource file was tedious but not too problematic. I fixed a few existing minor bugs which became apparent during this process, so this version is actually slightly better than the original. A reply to an email had to be stored in two places: on the one hand, the text of the reply and the reasons had to be stored in the output file (which will eventually be read into the database), whereas on the other hand, the text has to be kept in memory as it has to be rereferenced should the examinee decide to reply to one of his own emails. I solved this by defining a record type (which inherits from TObject) and storing the replies in a TList. Debugging was a bit awkward but eventually I got all the bugs out and even improved the program a little by displaying replies in a different colour.

But I had also lost something: I would need a separate exam program for every exam (ie one exe file runs the demonstration exam, one exe file runs the furniture exam, etc). Whilst this is not too annoying, it is somewhat impractical. The solution is to store each resource file in a dll; the program scans the list of dlls in the current directory and displays them in a combo box (on the form where the user enters her details). The dll chosen is then passed to the 'LoadLibrary' function, and all future resource references are made to the handle of the dll library. Maybe complicated to explain, but this didn't take very long to implement.

This is quite a step forward in Windows programming for me.

No comments: