I wrote at the beginning of September that Embarcadero has decided to make the current version of Delphi (10.2) free to freelance developers, startups, students and non-profits. After playing with it for some time, I discovered that it does not come with the components which I used for connecting to the Firebird database server, meaning that I would have to translate all the code which I currently have into new code. This is the same as I did several years ago when I transferred old BDE code to Firebird. I don't have the time to do this now, and there is no guarantee that my copy of 10.2 Delphi will work after September 2019.
I also wrote that writing a translator from Excel's newish XLSX format to tab delimited seemed possible with the new Delphi. This took about an hour as I had to figure out new components. I tried the program out and it seemed to work fine.
But there were problems every time that I ran the converter on real files at work. The program is command line driven, so that it can be called from Priority. I could see that the program was being invoked but nothing was happening. After spending no small amount of time on this (and figuratively knocking my head against a brick wall), I decided to write a manually driven program to convert input files, thus allowing me to concentrate on writing whatever code was needed in Priority.
But the fact that my program worked once but not afterwards continued to niggle me so I decided to spend some time debugging with a clean head. First I wrote a very simple 'Hello world' program to verify that Priority was invoking my program. Then I expanded the program to print its parameters. This is where the penny dropped. Assuming that I had a command line like 'x:\1\soul and pepper.xlsx', the default command line parser in the Delphi program saw that there were three parameters: 'x:\1\soul', 'and' and 'pepper.xlsx'! As my program checks to see whether exists a file which matches the first parameter ('x:\1\soul'), it is not surprising that the program did not continue - although the error logging should have displayed that the file does not exist.
OK, where to go from here? My first thought was that I should correct my Delphi program, but this was going to be problematic as there are supposed to be three parameters to the program (the input file, the output file and flags). Handling these parameters when the input file could in itself produce several parameters seemed problematic.
My next thought was to enclose the input file name with quotation marks - "x:\1\soul and pepper.xlsx". The Delphi program should see this as one file, but I couldn't get Priority to do this (string operations are problematic in Priority). I then wrote some complicated and ultimately stupid code to convert spaces in the filename to underscores - this gave me 'x:\1\soul_and_pepper.xlsx', which worked. Priority has a way of copying files which ignores the space problem, so I copied the original file to the new file and called my converter with this new name.
Then I had the proper insight: copy the original file - whatever its name - to a new file whose name I control (no spaces!), then convert the new file. Simplicity. Now my converter program works properly!
No comments:
Post a Comment