Avatar of Stevie2000
Stevie2000
 asked on

Altering SysUtils

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

Cheers
Delphi

Avatar of undefined
Last Comment
Wim ten Brink

8/22/2022 - Mon
Mike Littlewood

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?
ASKER CERTIFIED SOLUTION
Johnjces

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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.
Mike Littlewood

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.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Wim ten Brink

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?
alkisg

http://fastcode.sourceforge.net 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...
Stevie2000

ASKER
Good idea, it worked.

Shouldn't affect other packages should it?

Everything else is still working anyway.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Wim ten Brink

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.)
Stevie2000

ASKER
MY project does have third party components and packages, but everything is still working as it should be.
Wim ten Brink

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?
Your help has saved me hundreds of hours of internet surfing.
fblack61