-3

My company has been using Delphi for decades, and our core program was made in a quite old version. It has about 1.3 million lines of code.

After upgrading to Delphi 10 Rio, a major problem occured. Where our local function variables used to be initialized with a default value (integer would be 0, boolean would be false), it seems they no longer are. Now all my variables get a random value as they are created, so an integer gets something like 408796 as it's value.

I suppose this isn't an issue with new development, but I am sure you can see the problem in our large code base. We have never manually assigned default values to these variables as it worked fine. Object variables, however, have always had this problem. All properties get random values, so we have adressed that as we went. But now our program completely breaks, as all counters etc. are starting at high values instead of 0. And running through the entire project to fix this would take months.

Is there perhaps a compiler option to change this? Seems very backwards that they would have changed this intentionally, as it would be pretty stupid. Why remove functionality that all developers expect? I had actually expected it to go the other way, that object variables would no longer need manual default values, and that they maybe implemented a garbage collector. But is seems Delphi has seriously regressed?

If there is some option to fix this, PLEASE let me know.

6
  • 1
    Heap variables are still initialized; that's something that has been around for ages. It would be better if you were more specific about the issues you're having, since without the detail, everything is pure guesswork. Sep 20, 2019 at 9:27
  • 1
    From which version did you upgrade? You should actually provide detailed examples of code that you are having trouble with. Please do so. Sep 20, 2019 at 9:44
  • 1
  • 1
    "Where our local function variables used to be initialized with a default value (integer would be 0, boolean would be false), it seems they no longer are." No, local integer and boolean variables have never been initialized. Sep 20, 2019 at 10:05
  • 3
    I'm positive that you've misdiagnosed the problem. It's simply not possible for a sizeable application to survive all those years without initializing local variables. Sep 20, 2019 at 14:02

1 Answer 1

8

Local variables of unmanaged types such as integer and boolean have never been initialized automatically. If you have code that relies on that, that code has always been broken. If your program has not been affected then that has been down to chance rather than planning. Had you enabled compiler hints and warnings, the compiler would have told you this.

All variables of managed types are default initialized. All global variables are default initialized. All class member fields are default initialized. It is just local variables of unmanaged types, and memory allocated dynamically with GetMem that is not default initialized.

Your only path forward is to fix your code to make sure that variables are initialized. Use the compiler hints and warnings to help you.

Not the answer you're looking for? Browse other questions tagged or ask your own question.