Resolving Internal Errors (Delphi)

From RAD Studio
Jump to: navigation, search

Go Up to How To Use the Debugger


The error message Internal Error - X1234 indicates that the compiler has encountered a condition, other than a syntax error, that it cannot successfully process.

Tip: Internal error numbers indicate the file and line number in the compiler where the error occurred. This information can help Technical Support services track down the problem. Be sure to record this information and include it with your internal error description.

To resolve an internal error

  • If the error occurs immediately after you have modified code in the editor, go back to the place where you made your changes and make a note of what was changed.
  • If you can undo or comment out the change and then recompile your application successfully, it is possible that the programming construct that you introduced exposed a problem with the compiler. If so, follow the procedure on reviewing code below.

If the problem still exists

  1. Delete all of the .dcu files associated with your project.
  2. Close your project completely using File > Close All.
  3. Reopen your project. This will clear the unit cache maintained in the IDE. Alternatively, you can close the IDE and restart.
  4. Another option is to try and recompile your application using the Project > Build option so that the compiler will regenerate all of your dcus.
  5. If the error is still present, exit the IDE and try to compile your application using the command line version of the compiler (dccil.exe) from a command prompt. This will remove the unit caching of the IDE from the picture and could help to resolve the problem.

Review your code at the last modification point

  1. 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, 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.

begin
	if Integer(b) = 100 then...
end;
var
 a: Integer;
begin
  a := b;
  if a = 100 then...
end;		
Here is an example of unexpected code that you can correct to resolve the error:
var
 A : Integer;
begin
 { Below the second cast of A to Int64 is unnecessary; removing it can avoid the Internal Error. }
 if Int64(Int64(A))=0 then
end;
  1. In this case, the second cast of A to an Int64 is unnecessary and removing it corrects the error. If the problem seems to be a while...do loop, try using a for...do loop instead. Although this does not actually solve the problem, 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 it means that the manner in which you wrote your code was unexpected.
  2. After you have identified the problem, we ask that you create the smallest possible test case that still reproduces the error and submit it to Embarcadero.

Other techniques for resolving internal errors:

  • If the error seems to be on code contained within a while...do loop, try using a for...do loop instead or the other way round.
  • If it uses a nested function or procedure (a procedure/function contained within a procedure/function), try unnesting them.
  • If it occurs on a typecast, look for alternatives to typecasting like using a local variable of the type you need.
  • If the problem occurs within a with statement, try removing the with statement altogether.
  • Try turning off compiler optimizations under Project > Options > Compiler.

When all else fails

  • Typically, there are many different ways to write any single piece of code. You can try and resolve an internal error by changing the code. While this may not be the best solution, it may help you to continue to work on your application. If this resolves the problem, it does not mean that either while loops or for loops are broken but perhaps that the manner in which you have written your code was unexpected and therefore resulted in an error.
  • If you have tried your code on the latest release of the compiler and it is still reproducible, create the smallest possible test case that will still reproduce the error and submit it to Embarcadero. If it is not reproducible on the latest version, it is likely that the problem has already been fixed.

Configuring the IDE to avoid internal errors

  • 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 > Environment Options, select the Library tab and set the DCP output directory to C:\DCP. This setting will help ensure that the .dcp files the compiler generates are always up-to-date. This is useful when you move a package from one directory to another. You can create a .dcu directory on a per-project basis using Project > Options > Directories/Conditionals > Unit output directory.
  • The key is to use the most up-to-date versions of your .dcu and .dcp files. Otherwise, you may encounter internal errors that are easily avoidable.

See Also