Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip sourcecode in background (kibitz) compiler

Tags:

delphi

I have a problem with the background compiler in Delphi7: in my project there is a single line of code that causes the background compiler to stop with an error message so that no CodeCompletion is possible. The normal compiler and the syntax check have no problem with this code and the resulting application is correct.

My question is if there is any way to skip this codeline when the background compilation is performed (e.g. compiler directive).

Example code to reproduce the error:

procedure ProduceKibitzError;
var
  v : Variant;
begin
  v.End; // This line stops kibitz compiler
end;

This code is placed in a unit "Error.pas" which is used in the main unit. If you try to call CodeCompletion in the main-unit, it stops with the message "Error.pas could not be compiled" (real message is in german).

Interestingly the error only occurs until the project is compiled or syntax check is performed for the first time. After compilation the CodeCompletion is working and Delphi has to be restarted to reproduce the error.

Update: Adding an empty Assembler block with an end label is a solution for the problem. Here is the changed example code that doesn't stop the background compiler:

procedure ProduceKibitzError;
var
  v : Variant;
begin
  asm
    @@END:
  end;
  v.End;
end;

Many thanks,

Christian

like image 501
user153642 Avatar asked Dec 10 '22 19:12

user153642


1 Answers

The background compiler does not do procedure body analysis when parsing to get to the position of the cursor. Instead, it uses simple syntax matching (such as begin/end pairs). If simple syntax matching indicates that the final end in the unit has been met, then it exits early.

This is what's happening with your example. The first End token is not escaped by the late binding logic because it's not being parsed by the real expression compiler, and instead it's being read as the end of the procedure. The second end looks like the end of the unit, and the background compiler never sees any further.

Added: You might try adding an empty asm/end block to this routine. It prevents the kibitz compiler skipping procedure analysis. Graphics.pas has an asm/end block with an @@end label, and the compiler handles asm/end blocks specially because of it.

like image 186
Barry Kelly Avatar answered Jan 01 '23 23:01

Barry Kelly