5

I need (to make some quick and dirty tests) to modify the code of Variants and SysUtils.

What I need to do to "compile" the changes?

I can of course open those units in the IDE, but if I change them and I buoild a project again I don't see those units recompiled.

What is needed to be done?

UnDiUdin
  • 14,924
  • 39
  • 151
  • 249
  • create your new datatypes and make the tests with the new ones – RBA Mar 29 '12 at 09:20
  • 3
    My question is: Why do you think you have to modify these files? Because often you can achieve that by other ways. – Stefan Glienke Mar 29 '12 at 10:16
  • Generally you should not do that. Especially not for units in the RTL (Variants/SysUtils). Anything you're thinking of doing is either a bad idea, or won't work, or both. – Warren P Mar 29 '12 at 16:10

4 Answers4

7

The problem is you would need to compile ALL of the RTL/VCL against the 'new' units.

Instead modify a copy of the units in question and add them to your project when you want to use them. Delphi should use these over those in the RTL/VCL.

Lloyd
  • 29,197
  • 4
  • 84
  • 98
  • 7
    This will work so long as you only make changes in the implementation section of the units, and so long as you compile these units with the same compiler options as used when Emba originally compiled the unit. – David Heffernan Mar 29 '12 at 09:01
  • 1
    I tried to create a new unit called Sysutils, added it to my project, completely copying System.Sysutils code and modified it (only in implementation). Anyway if from dpr I CTRL_Clcik sysutils.pas it opens System.Sysutils, not my new unit. – UnDiUdin Mar 29 '12 at 09:07
  • 1
    @user If you add it to your project, then it's the one that is compiled. The IDE might get confused but try stepping through under the debugger and you should land in your code. – David Heffernan Mar 29 '12 at 09:09
  • @DavidHeffernan - really? I just copied Const.pas into my project and localized some strings, and worked (I think there is a better, cleaner way to translate strings from Const.pas but I was in a rush.) What do you mean the same compiler options? – Leonardo Herrera Mar 29 '12 at 15:51
  • @LeonardoHerrera Yes really. Const.pas isn't a typical unit. It's just a list of declarations. Take a more normal unit, e.g. StdCtrls. Try adding a field to one of the classes in the interface section. As for compiler options, you know what I mean, alignment, short-circuit boolean eval, typed address etc. I always use typed address in my projects but VCL does not. So my customised VCL units have to include a bunch of compiler options at the top of the unit. – David Heffernan Mar 29 '12 at 16:04
  • Only the "interface" part of the unit should be untouched. See my answer. – Arnaud Bouchez Mar 29 '12 at 16:10
  • That kind of rushing only slows you down, Leonardo. – Warren P Mar 29 '12 at 16:11
  • @WarrenP - I understand what you mean. But sometimes a hack is needed, even if it is only temporary until we get time to properly understand and solve the issue. – Leonardo Herrera Mar 29 '12 at 19:22
5

Unless you do not change the interface part of the unit (that is, you only modify the implementation side), you can make your own version of the RTL units (only exception is System.pas and SysInit.pas, but this is not in your scope - see our blog site for some enhancements of those units).

What you need is to put your own version of Variants.pas and SysUtils.pas in the search path of your project. They will be taken in account instead of the default RTL.

But be aware that you may easily break anything.

For testing purpose, this is OK, but if you want to use those modifications, you shall better use some automated regression tests, and know explicitly what you are doing.

Please note that you can use the "debug" version of the RTL units (from the project options), then step with the debugger within the official source code. It may help finding issues without touching the source.

If you change the interface part of the unit, you'll have to recompile all units which call the modified unit - for SysUtils and Variants, this is almost all RTL.

Arnaud Bouchez
  • 42,305
  • 3
  • 71
  • 159
  • Presumably it's against the license to redistribute code linked against modified vcl units? – David Heffernan Mar 29 '12 at 18:38
  • 1
    Yes it is against the Borland/Embarcadero license. That's why we deliver our enhanced versions in form of patches. See http://blog.synopse.info/post/2010/01/05/New-Enhanced-System-Run-Time-Distribution – Arnaud Bouchez Mar 30 '12 at 09:44
2

Delphi runtime DCUs are precompiled. It would be a waste of time to compile them at every build.

If the code you are trying to modify is a method of a built-in class, then a class helper may help:

http://docwiki.embarcadero.com/RADStudio/en/Class_and_Record_Helpers

So the question is which part of code do you want to modify in the runtime?

hubalazs
  • 448
  • 4
  • 13
0

If you really wish to recompile the RTL you can do so (Make a backup first!). Versions of Delphi prior to Delphi 2010 had a makefile in the source folder that could be run from the command line to rebuild the rtl/vcl. I don't know for sure (I'm still using D2009) but from what I've heard this file is no longer present in newer versions. Hopefully there is an alternative. Otherwise you would wind up wasting a lot of time trying to guess that the compiler settings for each unit.


If you wish to "patch" a bug in the rtl for your project only you can copy the unit you want to modify into your project's folder and make your change. If the unit your modifying is used throughout the RTL/VCL you may find yourself copying quite a few dependent units into your project folder in order for it to compile.

If this significantly slows down the compile time for your project you can always do your initial compile then remove the "patched" units, leaving behind the compiled dcus.

Kenneth Cochran
  • 11,954
  • 3
  • 52
  • 117