Can I recompile .PAS files used by the Delphi development environment?

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?

+4
source share
7 answers

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

+12
source

See previous answers on how to create a situation where you can recompile a modified VCL source. However, I would add that you are serious about managing change in your change management system using the SCM SCM Provider template.

In simple terms (using SVN as a reference):

  • Create a copy of the vendor-supplied source code. This is your “original” reference copy.

  • Create a branch representing this blank copy (for example, “2009” for the VCL version of Delphi 2009)

  • create a new branch in a separate folder "provider library". THIS is a copy of the library that you should reference in your projects.

  • any changes in the source of the supplier are made in the branch "supplier library".

  • when the provider provides a new version of the library that you are checking in the new version, in the project "source of the supplier" and create a new branch for the new version.

You can easily distinguish between vendor versions. But more importantly (with SubVersion, and possibly with SCM systems), you can also simply merge (that is, automatically) the new vendor source with the vendor library branch to easily make changes to the vendor with your own changes.

All of this is described much better than I did in O'Reilly's excellent book: Version Control with SubVersion

NOTE, however, that the "loaddirs" utility mentioned in this book is no longer supported due to copyright issues, so updating the "performance degradation" is currently a manual exercise, but this is rare and is not a major burden.

We ourselves use this template, although in the case of VCL we do not save a full copy of the entire VCL source tree in our "vendor source" or "supplier library", but instead only track the changed and dependent units, For other libraries managed in the vendor branch, we usually support full copies, but decided it was not necessary for VCL.

However, we just implemented this template, so we can decide that we need to use a more complete approach to VCL as well.

Ymmv

+4
source

You can, but often you don’t need it. Recompiling the VCL module once meant recompiling all the other VCL units, either because you changed the device interface, or because the compiler got confused and thinks you changed the interface. Recompiling the VCL module also precludes the use of most runtime packages, since you cannot recompile Delphi runtime packages.

Instead of recompiling, you can use fixes at runtime. I used the method in TNT Unicode controls , but Madshi also provides the ability to replace a function with its own implementation. If you copy the implementation of DBCommon.GetIndexForOrderBy into your own block and make your corrections, you can use this command to fix the VCL version with your own:

 var Old_GetIndexForOrderBy: Pointer; HookCode(@DBCommon.GetIndexForOrderBy, @Fixed_GetIndexForOrderBy, Old_GetIndexForOrderBy, 0); 

In the Unicode Tnt library, find the OverwriteProcedure routine in the TntSystem module. It is not publicly available, so you need to either declare it in the device interface or copy it into your own block. Then you can call it the same as Madshi code above:

 var Old_GetIndexForOrderBy_Data: TOverwrittenData; OverwriteProcedure(@DBCommon.GetIndexForOrderBy, @Fixed_GetIndexForOrderBy, @Old_GetIndexForOrderBy_Data); 
+4
source

We have a folder under our project source tree called VCL, in which we put copies of the VCL source that we want to change a bit. Your example is a good candidate to do the same. You will need to change the search path for your project so that the “your” VCL folder is earlier in your path than the “Source” folders in your Delphi installation. You may also find that if you copy one VCL source block and modify it, you will also have to copy the other VCL source blocks to your folder, which may be dependent.

Our reason for this is because we want our assemblies to have null hints and compiler warnings. There are some parts of the VCL source that are not prompts / warnings.

+2
source

"I’m familiar with Jeff Atwood’s article about how errors are always a programmer’s error, but I believe that I really and really found the error in the Delphi.pas file

Are you kidding me? With Delphi you always blame Borland in the first place :) Something is strange, go to Google and see if this is a Delphi error. Only if you cannot find any similar reports, you will be taken to the site and check your code line by line.

After reinstalling Delphi, I have to fix the source PAS files in 6 (six) places. There are tons of bugs that appear on the new Delphi installation and can be easily reproduced. Delphi (the one we all love) is full of mistakes. Around this, a whole story is being created. There are so many people releasing external patches (such as http://andy.jgknet.de/blog/?page_id=288 ) and Borland / Imprise / GoGear / Embarcadero continue to ignore them. It is a real miracle that they included FastMM in their release.

In any case, I recompiled these PAS files, and now I am replacing the original DCUs with the corrected ones.

+2
source

Just - Yes. Using one of the above answers [Tom or Connor]. Copy DBCommon.pas to the project folder, and do not edit the original. This leaves other projects and compilations unaffected because it will not be in the way.

+1
source

You can set: DataSetProvider.Option.poRetainServerOrder = True

+1
source

All Articles