The Total lines
the compiler tells you is counting the number of lines in the unit(s), regardless of what code is (or isn't) there. It even counts blank lines. Start a new project. Compile it and note the number of lines it says (mine says 42). Then, add just one line break somewhere, and compile again. It will claim there is one more line of code (43). So it does not seem the compiler takes any code into consideration for this number - only the actual line breaks.
In fact, if you add the total number of lines in the main form's unit (new project) as well as the project's main file, it will total to 2 less than what the compiler tells you (40 out of 42). So I wouldn't trust this number to mean much other than a rough estimate.
Libraries such as VCL, RTL, and Indy are not included in this count because those are pre-compiled. It is possible that your project might refer to a library or external unit which needs to be compiled, thus it will also include those into the count.
As far as your mention of how it counts if..then..else
blocks, keep in mind that your 5 lines of code can be combined into just 1 line of code (stripping line breaks) and it will still compile, and the compiler will count only 1 line, not 5 lines.
EDIT
Years later, and I'd like to add a trick that I've learned to get a more accurate count of YOUR lines of code...
- Do a full build of the project.
- Open and make a small change to each and every one of YOUR units (such as just adding a space somewhere), and save changes.
- Do a compile (not build) of the project.
- Observe the lines of code it reports.
Since other units already have their DCU, and no changes have been made to them, the compiler doesn't recompile them. It only compiles those units which have actually changed since the last compile.
Build forcibly compiles everything in your project no matter what - and that might include third-party units that your project just happens to use. Unless the package has been marked for "Explicit Rebuild".
By default, new packages in Delphi are marked as "Rebuild as needed", meaning it will rebuild any units you use from such package. But when releasing a package, it's common to change this "Build control" setting to "Explicit rebuild", that way it will not be rebuilt with your project (only linked). And thus not contributing to your LOC.