I have known about the dangers of using the with statement for a long time now. Today, I encountered a new one. I was refactoring code in a datamodule used to iterate over a dataset and insert each record into the database (a common construct). The numerous ParamByName() calls were enclosed in a ‘with query do’ and I received a run-time error in a FieldByName() call. The FieldByName() was to be called on the dataset which was not yet part of a with clause so it resolved to the query and of course the field didn’t exist. A classic problem with using FieldByName() exacerbated by the with statement.
The issue I didn’t expect, was when I tried to modify the with statement the XE4 IDE stopped responding. I waited a few seconds thinking it would come back after the the parser finished. It didn’t. I decided to go for lunch…when I came back about 20 minutes later the IDE was still unresponsive and I had to kill the process. Thankfully I have always enabled the Autosave options in the IDE, so I didn’t really lose any work.