Mirror

Runtime errors during loading of an application (Views: 300)


Problem/Question/Abstract:

A short detective story of strange runtime errors in Delphi

Answer:

The Crime

“It was a nice day when if happened. Everything worked fine. I just had to replace one 3rd-party component. Everything compiled with the new version. The problem started when I tried to run the application with the new components. When the application started, it shot-out a fatal runtime error 217, no matter what I did. Compiling the application with or without runtime packages had no affect, nor did including or excluding debug info. Whatever I did, I got the same message.”

The Plot Thickens

The first thing I did was to check what is runtime error 217. Guess what – in Delphi help, it is written “EControlC is the exception class for Ctrl+C key presses in console applications.”
Well, this explanation does not provide any help, for a number of reasons:

The application is not a console application, but a GUI application.
Who the hell did press Ctrl+C ???

The investigation

First, I tried to place a break point in the dpr file.

The code is:

begin
  Application.Initialize;
  Application.CreateForm(TfrmMain, frmMain);
  Application.CreateForm(TdmReoprtObj, dmReoprtObj);
  Application.Run;
end.

When I placed the break point on the “Begin” line, the application reached that line.
When I placed the break point on the next line – “Application.Initialize”, the application did not reach that line.

Second, I tried to compile the application without runtime packages, with the hope that Delphi will point me to the offensive code, like Delphi does most of the time. This time was one of those times Delphi decided not to help. I had to find the problem my self.

Third, after some consultations, we (I and other code ‘detectives’) decided to go to broth force. We paced breakpoints everywhere - In the start of every initialization section in any unit. Here we found the problem.

When I replaced the 3rd-party component, the new version added a new class to the game, lets call it TOffecsiveClass. The 3rd-party component also registered the class:

RegisterClasses([TOffecsiveClass]);

In my code, we had another class, named also TOffecsiveClass, that was registered using the same function.
The result was that we registered the same class twice, there for getting an exception in the initialization section of a unit.

Conclusion

Runtime error 217 is not a Ctrl+C console application error.
If you have an exception in the initialization or finalization sections of a unit, don’t expect to get a nice message. Most likely, you’ll get a runtime error (216 or 217).
If you get runtime errors during the loading of the application, or during the shutdown of it, check the initialization and finalization sections.

<< Back to main page