I am familiar with Jeff Atwood, an article on how errors are always a programmer's error , but I believe that I really and really found an error in the Delphi.pas file.
In particular, I am using Delphi 2007, and the error is on line 955 of the DBCommon.pas file, which is located on my machine:
C: \ program files \ codegear \ rad studio \ 5.0 \ source \ Win32 \ db \ DBCommon.pas
And the code is this:
... FieldIndex := StrToInt(Token); if DataSet.FieldCount >= FieldIndex then LastField := DataSet.Fields[FieldIndex-1].FieldName else ...
If the “token” has a value of 0, we are trying to access the -1 index from the DataSet.Fields, which leads to an index index error outside the bounds.
This error does not occur for the user, because it is processed before it becomes so high, but it is extremely dangerous for the debugger to interrupt every time this happens.
I could "ignore this type of exception", but Index out of bound errors are quite common, and I don't want to ignore them.
The situation that makes FieldIndex equal to zero is that you have a SELECT statement whose ORDER BY contains a function, for example:
ORDER BY CASE WHEN FIELD1 = FIELD3 THEN 1 ELSE 2 END ,CASE WHEN FIELD2 = FIELD4 THEN 1 ELSE 2 END
I can fix the error in DBCommon.pas, but Delphi will not recompile itself, and my changes will not take effect. If I rename the .DCU file, then it just complains that “DBCommon.dcu” could not be found.
So (finally) my question is: can I recompile DBCommon.pas with my fix, and if so, how?