Explanation of "Internal Error" (Views: 14842)


Occasionally when compiling an application in Delphi compilation will halt with an error message that reads "Internal Error: X1234" (this is just an example). While this error seemingly means very little to the end user there are steps one can take to try and resolve the problem.


Let's start with an explanation of the error message. "Internal Error" indicates that the compiler has encountered a condition, other than a syntax error that it cannot successfully process. The information following "Internal Error" is usually one to three characters immediately followed by a number that indicates the file and line number inside the compiler itself where the error occurred. While this information isn't helpful to the enduser it can help Borland track down the problem if/when it is reported.

What to do when you encounter an "Internal Error"

Should you encounter an internal error there are a few steps that you can take to try and resolve the problem.

If the error occurs immediately after you have modified code in the editor go back to the spot where you made your changes and make a note of what was changed.

If you can undo or comment out the change and recompile your application successfully it is possible that the programming construct that you were using previous exposes a problem with the compiler so jump down to step 7. If not try, the next few steps to resolve your problem.

Delete all of the .DCU files associated with your project.

Close your project completely using File | Close All, then reopen your project, this will clear the unit cache maintained in the IDE. Alternatively you can simply close the IDE and restart.

Another options is to try and recompile your application using the Project | Build option so that the compiler will regenerate all of your DCUs.

If the error is still present exit the IDE and try to compile your application using the command line version of the compiler (dcc32.exe) from a command prompt. This will remove the unit caching of the IDE from the picture and could help to resolve the problem.

If the problem still exists go back to the place where you last made modifications to your file and review the code. Typically, most internal errors can be reproduced with only a few lines of code and frequently the code involves syntax or constructs that are rather unusual or unexpected. If this is the case you can try modifying the code to do the same thing in a different way. For example, if you are typecasting a value try declaring a variable of the cast type and do an assignment first.

Like this:

  if Integer(b) = 100 then

  a: Integer;
  a := b;
  if a = 100 then

Here is an example of unexpected code which can be corrected by the developer to resolve the error:

  A: Integer;
  if Int64(Int64(A)) = 0 then

In this case the second cast of A to an In64 is unnecessary and removing it allows the compiler the compile successfully.

If the problem seems to be a "while...do" loop try using a "for...do" loop instead. While this is clearly not the best solution it may help you to continue work on your application. If this resolves the problem it does not mean that either "while" loops or "for" loops are broken but more likely the manner in which you've written your code was unexpected.

Another tip is to create a single directory where all of your .DCP files (precompiled package files) are placed. For example create a directory called C:\DCP and under Tools | Enviroment Options select the Library tab and set DCP output directory to C:\DCP. By making this setting it will help to ensure that the .DCP files that the compiler uses are always the most recent version which is particularly useful when you move a package from one directory to another.

<< Back to main page