Delphi – recompile the .PAS files used by the Delphi IDE

delphidelphi-2007

I am familiar with Jeff Atwood's article about how errors are always the programmer's fault, but I believe I have really and truly found a bug in a Delphi .pas file.

Specifically, I'm using Delphi 2007, and the error is on line 955 of the DBCommon.pas file, which on my machine is located here:

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 "Token" has a value of zero, then we try to access index -1 of DataSet.Fields, resulting in a list index out of bounds error.

This error is not raised to the user, because it is handled before it gets that high up, but it is enormously irritating to have the debugger break in every time this happens.

I could "Ignore this exception type" but Index out of bounds errors are common enough that I don't want to universally ignore them.

The situation that causes FieldIndex to be zero is when you have a SELECT statement whose ORDER BY contains a function, as in:

ORDER BY
  CASE WHEN FIELD1 = FIELD3 THEN 1 ELSE 2 END
 ,CASE WHEN FIELD2 = FIELD4 THEN 1 ELSE 2 END

I can fix the bug in DBCommon.pas, but Delphi will not recompile itself, and my change does not take effect. If I rename the .DCU file, then it just complains that "DBCommon.dcu" cannot be found.

So (finally) my question is: Can I recompile DBCommon.pas with my fix, and if so, how?

Best Answer

You can probably put dbcommon.pas in youre project directory. It will then be compiled along with the rest of the project.

Related Topic