Recent

Author Topic: Question about include files  (Read 828 times)

440bx

  • Hero Member
  • *****
  • Posts: 5805
Question about include files
« on: September 13, 2025, 02:47:47 pm »
Hello,

I'd like to have documentation for some parts of a program in include files and, ideally have Lazarus jump/open the include file if directed to do so.

In code the idea is as follows:
Code: Pascal  [Select][+][-]
  1.  
  2.  
  3. program _IncludeDoc;
  4.  
  5.  
  6. begin
  7.  
  8.   {$ifdef NOT_DEFINED}
  9.     {$include DocPage.inc}
  10.   {$endif}
  11.  
  12.   readln;
  13. end.                    
  14.  
if the programmer right-clicks on DocPage.inc and selects "Find declaration of DocPage", Lazarus would open the DocPage.inc file in an editor window.

The problem is Codetools does not find the DocPage.inc file because it is in the "NOT_DEFINED".  Commenting out the "ifdef/endif" combination solves the problem but this has two (2) undesirable side effects:

1. FPC opens the file, reads it and attempts to compile it.  That slows down compilation when there are many such files.

2. the contents of the file must be all comments, that is, every line must be preceded by a // or be in a comment block { } or (* *).  It would be nicer if the file could contain just plain text.

The question is: is there a way to have the "Find declaration of DocPage" work without having to make it visible to FPC ?

Attached is a tiny project with the above code and a sample doc file.

Thank you for your help.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

LV

  • Sr. Member
  • ****
  • Posts: 358
Re: Question about include files
« Reply #1 on: September 13, 2025, 03:32:43 pm »
I'd like to have documentation for some parts of a program in include files and, ideally have Lazarus jump/open the include file if directed to do so.

Hello!
If I understand correctly, this does what you want (see screenshots).

440bx

  • Hero Member
  • *****
  • Posts: 5805
Re: Question about include files
« Reply #2 on: September 13, 2025, 03:55:54 pm »
Hello!
If I understand correctly, this does what you want (see screenshots).
Yes, it does!

I missed the "elephant in the room" ;)

Thank you, that's exactly what I wanted. :)
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

LV

  • Sr. Member
  • ****
  • Posts: 358
Re: Question about include files
« Reply #3 on: September 13, 2025, 04:05:10 pm »
You're welcome. Thanks to the Lazarus developers.  :)

PascalDragon

  • Hero Member
  • *****
  • Posts: 6184
  • Compiler Developer
Re: Question about include files
« Reply #4 on: September 14, 2025, 08:48:29 pm »
The question is: is there a way to have the "Find declaration of DocPage" work without having to make it visible to FPC ?

Just in case you should have that problem for something else where there isn't a suitable work around available: you can have the IDE declare a define that's only visible for the IDE, but not the compiler. To quote from the Rtti unit in 3.2.2 where I made use of this when Lazarus didn't support generic functions:

Code: Pascal  [Select][+][-]
  1. { Note: since the Lazarus IDE is not yet capable of correctly handling generic
  2.   functions it is best to define a InLazIDE define inside the IDE that disables
  3.   the generic code for CodeTools. To do this do this:
  4.  
  5.   - go to Tools -> Codetools Defines Editor
  6.   - go to Edit -> Insert Node Below -> Define Recurse
  7.   - enter the following values:
  8.       Name: InLazIDE
  9.       Description: Define InLazIDE everywhere
  10.       Variable: InLazIDE
  11.       Value from text: 1
  12. }
  13. {$ifdef InLazIDE}
  14. {$define NoGenericMethods}
  15. {$endif}
  16.  

440bx

  • Hero Member
  • *****
  • Posts: 5805
Re: Question about include files
« Reply #5 on: September 14, 2025, 11:05:32 pm »
@PascalDragon,

I don't see how what you suggested can solve the problem I mentioned.  I would appreciate it if you could elaborate and ideally provide an example.

Thank you in advance.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

PascalDragon

  • Hero Member
  • *****
  • Posts: 6184
  • Compiler Developer
Re: Question about include files
« Reply #6 on: September 16, 2025, 11:05:37 pm »
Assuming you have the IDE define InLazIDE like I showed above then you can do the code from your initial post like this:

Code: Pascal  [Select][+][-]
  1. program _IncludeDoc;
  2.  
  3.  
  4. begin
  5.  
  6.   {$ifdef InLazIDE}
  7.     {$include DocPage.inc}
  8.   {$endif}
  9.  
  10.   readln;
  11. end.

This means the IDE will assume that the ifdef is active while the compiler will consider it as inactive.

440bx

  • Hero Member
  • *****
  • Posts: 5805
Re: Question about include files
« Reply #7 on: September 16, 2025, 11:27:20 pm »
This means the IDE will assume that the ifdef is active while the compiler will consider it as inactive.
Now I understand.  That's perfect, thank you. :)

FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018