Link to home
Start Free TrialLog in
Avatar of Stevie2000

asked on

Altering SysUtils

How can I alter SysUtils and get Delphi to acknowledge the changes?  Do I need to recompile a package?

Avatar of Mike Littlewood
Mike Littlewood
Flag of United Kingdom of Great Britain and Northern Ireland image

Its just a utility unit with code so I don't think you need to recompile it (except to check if the changes you made are fine).
Wouldnt it be safer just to override a function you want to use instead of altering the core delphi though?
Avatar of Johnjces
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kyle Foster
Not so simple, if you recompile the SysUtils unit then any unit such as System that uses the unit will have to recompile... you will get a mismatch error saying the unit was compiled with an earlier version of the library and you are dead in the water.

What is your issue with SysUtils?  That is probably the best place to start.
I think Johns idea is the best.
Take a copy of it and put it in the same location as your project.
You can then just include it in your application then and change it without affecting the main one.
Changing SysUtils? Why would someone ever want to do that? Basically, if you do that, all other packages that rely on SysUtils will need to be rebuild too. And if you don't have the sourcecode of those units then well, you're Doomed... :-)
Anyway, you can simply rebuild Sysutils by executing the MakeFile in the source folder. (It's C:\Borland\Delphi7\Source\Rtl|Makefile or C:\Borland\Delphi 2006\source\Win32\rtl on my system, depending on the Delphi version.)

Keep in mind that if you recompile SysUtils then you might also have to recompile every unit that depends on this unit. Considering how many packages will be using this unit, I think you might have to recompile all your packages. What if you don't recompile the other packages? I don't know. I suspect Delphi will give you dozens of warnings or errors or whatever. And worse, once you'll upgrade to a newer Delphi version (or install a patch) then you might have lost all those changes again.

Basically, if you need better functionality than SysUtils provides, just build a new unit instead and put the changes in there. What is it anyways that you needed to fix? uses a patching mechanism which overrides Delphi unit functions with user defined ones.

This is done at runtime: they modify the Delphi procedures code in RAM to JMP to their own procedures.
You could use the same method, it's just a few lines of code...
Avatar of Stevie2000


Good idea, it worked.

Shouldn't affect other packages should it?

Everything else is still working anyway.
It can affect packages, especially if you don't have the sourcecode of those packages. You will get a unit version conflict. Which is why it's bad (in general) to just replace the VCL units. But this is something you'll discover when you start working on some bigger projects. (Especially projects with third-party components.)
MY project does have third party components and packages, but everything is still working as it should be.
Well, the reason for that is probably because Delphi can find the source files of those packages and thus it will recompile them as need be. Delphi knows that these units depend on the SysUtils unit and thus if SysUtils has been recompiled then Delphi will recompile those sources too.
Also, some packages might not have a direct relationship with the SysUtils unit and thus they will have no problems with a recompiled SysUtils unit.

But while things are okay for now, it doesn't mean you're safe. First of all, some projects might refuse to build because the SysUtils unit has changed and Delphi is unable to recompile the sources for the files that depend on SysUtils. Of course when you get a patch for your Delphi version then the patch might cause some conflicts too, which will require you to adjust your own SysUtils version again. And when you upgrade to a newer Delphi version you'd have to redo your changes again. Not to mention the problems you could encounter if you decide to use runtime packages.

And of course, since you now have two copies of the SysUtils unit you'll never know for sure which source will be used for your project.

Which brings me to the question: why did you need to make changes to SysUtils in the first place? Why can't you add those changes to a new unit?