IDE directives: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: IDE directives
| Old | New | Line | |
|---|---|---|---|
| 1 | + | ## Contents | |
| 2 | + | ||
| 3 | + | * 1 Overview | |
| 4 | + | * 2 Hide one hint, note or warning | |
| 5 | + | * 3 File encoding | |
| 6 | + | * 4 Run/Build file | |
| 7 | + | * 5 Other IDE Directives | |
| 8 | + | * 6 Reading / finding IDE directives | |
| 9 | + | ||
| 10 | + | # Overview | |
| 11 | + | ||
| 12 | + | IDE directives are similar to compiler directives: a special kind of comment placed in your source code. They are enclosed by curly brackets with an opening percentage sign. For example: | |
| 13 | + | ``` | |
| 14 | + | {%H-} | |
| 15 | + | ``` | |
| 16 | + | ||
| 17 | + | The compiler sees them simply as comments which it ignores. The IDE uses these directives to store source-specific information which is independent of project and session. | |
| 18 | + | ||
| 19 | + | # Hide one hint, note or warning | |
| 20 | + | ||
| 21 | + | To hide a single hint, note or warning you use the following IDE directive: | |
| 22 | + | ``` | |
| 23 | + | procedure DoSomething({%H-}NotUsed: char); | |
| 24 | + | begin | |
| 25 | + | ||
| 26 | + | end; | |
| 27 | + | ``` | |
| 28 | + | ||
| 29 | + | This will suppress the line in the Lazarus Messges window that otherwise would report | |
| 30 | + | ``` | |
| 31 | + | Hint: Parameter "NotUsed" not used | |
| 32 | + | ``` | |
| 33 | + | ||
| 34 | + | The compiler still issues the Hint, but the {%H-} IDE directive causes the IDE to filter the Hint out of the Messages view. | |
| 35 | + | ||
| 36 | + | Note: You can right click on a hint in the message window and choose the context menu option "Hide message via directive" to insert the directive automatically. | |
| 37 | + | ||
| 38 | + | This feature was introduced in Lazarus 0.9.29. | |
| 39 | + | ||
| 40 | + | # File encoding | |
| 41 | + | ||
| 42 | + | You can specify what encoding the IDE should use for a source file by adding a BOM or an encoding directive at the very start of a source file: | |
| 43 | + | ``` | |
| 44 | + | {%encoding CP1250} | |
| 45 | + | ``` | |
| 46 | + | ||
| 47 | + | See the unit lcl/lconvencoding.pas for all possible values. | |
| 48 | + | ||
| 49 | + | # Run/Build file | |
| 50 | + | ||
| 51 | + | The IDE can run and build single files instead of projects. The parameters for building/running a file are stored as IDE directives within the file itself. | |
| 52 | + | ||
| 53 | + | * {%BuildCommand <command line used for building, default is $(CompPath) $(EdFile)>} | |
| 54 | + | * {%BuildWorkingDir <working directory, default is the file path>} | |
| 55 | + | * {%BuildScan <parsers>} List of parsers used for build output | |
| 56 | + | * {%RunCommand <command line used to run, default is $NameOnly($(EdFile))>} | |
| 57 | + | * {%RunWorkingDir <working directory, default is the file path>} | |
| 58 | + | * {%RunFlags <flags, default Build+>} where flags is a space separated list of options. E.g. {%RunFlags Messages+ Build+} | |
| 59 | + | * Build+ build before run, default: on | |
| 60 | + | * Messages+ show run output in the Messages window, default: off | |
| 61 | + | ||
| 62 | + | See [[IDE Window: Configure Build file|Configure Build File]]. | |
| 63 | + | ||
| 64 | + | # Other IDE Directives | |
| 65 | + | ||
| 66 | + | * {%Region} Allows you to define your own [[IDE Window: Editor Options Code Folding|Code Folding]] blocks, by putting this special comment into the code. You have to specify the end of the folded region with {%Endregion} | |
| 67 | + | * {%MainUnit path/to/unit.pas} Used as first line in an include file to give codetools a hint where the unit file is. Any **/** and **\** are converted to the current path delimiter. | |
| 68 | + | ||
| 69 | + | # Reading / finding IDE directives | |
| 70 | + | ||
| 71 | + | The codetools unit basiccodetools contains several functions for reading IDE directives: | |
| 72 | + | ||
| 73 | + | * FindNextIDEDirective | |
| 74 | + | * CodeToolBoss.GetIDEDirectives | |
| 75 | + | ||
| 76 | + | --- | |
| 77 | + | *From the Free Pascal wiki, page "IDE directives", as the Internet Archive kept it on 2025-03-23. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
