Sign in Join
Wiki copytemporary

IDE directives: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11# Overview
22
33IDE 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:
44
55``` pascal
66{%H-}
77```
88
99The 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.
1010
1111# Hide one hint, note or warning
1212
1313To hide a single hint, note or warning you use the following IDE directive:
1414
1515``` pascal
1616procedure DoSomething({%H-}NotUsed: char);
1717begin
1818
1919end;
2020```
2121
2222This will suppress the line in the Lazarus Messges window that otherwise would report
2323
24-`Hint: Parameter "NotUsed" not used`
24+```text
25+Hint: Parameter "NotUsed" not used
26+```
2527
2628The compiler still issues the Hint, but the {%H-} IDE directive causes the IDE to filter the Hint out of the Messages view.
2729
2830Note: 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.
2931
3032This feature was introduced in Lazarus 0.9.29.
3133
3234# File encoding
3335
3436You 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:
3537
3638``` pascal
3739{%encoding CP1250}
3840```
3941
4042See the unit lcl/lconvencoding.pas for all possible values.
4143
4244# Run/Build file
4345
4446The 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.
4547
4648- {%BuildCommand \<command line used for building, default is \$(CompPath) \$(EdFile)\>}
4749- {%BuildWorkingDir \<working directory, default is the file path\>}
4850- {%BuildScan \<parsers\>} List of parsers used for build output
4951- {%RunCommand \<command line used to run, default is \$NameOnly(\$(EdFile))\>}
5052- {%RunWorkingDir \<working directory, default is the file path\>}
5153- {%RunFlags \<flags, default Build+\>} where flags is a space separated list of options. E.g. {%RunFlags Messages+ Build+}
5254 - Build+ build before run, default: on
5355 - Messages+ show run output in the Messages window, default: off
5456
5557See [[IDE Window: Configure Build file|Configure Build File]].
5658
5759# Other IDE Directives
5860
5961- {%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}
6062- {%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.
6163
6264# Reading / finding IDE directives
6365
6466The codetools unit basiccodetools contains several functions for reading IDE directives:
6567
6668- FindNextIDEDirective
6769- CodeToolBoss.GetIDEDirectives
6870
6971---
7072*From the Free Pascal wiki, page "IDE directives", as it stood on 2020-02-17 after a change by Trev, out of the wiki's dump of 2024-05-26. 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).*

Back to history