In the code editor, {$IF DECLARED()} is always highlighted as true, regardless of whether the symbol is actually present
- Lazarus version: 3.6
What happens
Text inside {$IF DECLARED(symbol)}
blocks always appears active, even if the symbol specified is not actually declared anywhere. The {$ELSE}
block is therefore shown as inactive. Replacing $IF
with $IF NOT
reverses the situation, but still does not make it depend on the observable reality.
I haven't tested, but other predicates such as OPTION()
might have the same problem.
Steps to reproduce
program Project1;
begin
(* a variable from System unit *)
{$IF DECLARED(Output)} // https://www.freepascal.org/docs-html/3.2.2/rtl/system/output.html
WriteLn('declared Output'); // <-- shown as active, and actually is
{$ELSE}
WriteLn('not declared Output'); // <-- shown as inactive, and actually is
{$ENDIF}
{$IF NOT DECLARED(StdErr)} // https://www.freepascal.org/docs-html/3.2.2/rtl/system/stderr.html
WriteLn('declared StdErr'); // <-- shown as inactive, actually active
{$ELSE}
WriteLn('not declared StdErr'); // <-- shown as active, actually inactive
{$ENDIF}
(* non-existent symbol *)
{$IF DECLARED(symbol_that_DoEs_NoT_exist_asdfgsfds)}
WriteLn('declared FOOBAR'); // <-- shown as active, actually inactive
{$ELSE}
WriteLn('not declared FOOBAR'); // <-- shown as inactive, actually active
{$ENDIF}
{$IF NOT DECLARED(symbol_that_DoEs_NoT_exist_asdfgsfds)}
WriteLn('declared FOOBAR'); // <-- shown as inactive, and actually is
{$ELSE}
WriteLn('not declared FOOBAR'); // <-- shown as active, and actually is
{$ENDIF}
ReadLn();
end.
Edited by Dmitry D. Chernov