[Pas2js] does {$i} directive work for pas2js

Jean SUZINEAU Jean.Suzineau at wanadoo.fr
Fri Sep 18 21:43:19 CEST 2020


I imagine you refer to include file directive version of $I ( 
https://www.freepascal.org/docs-html/prog/progsu40.html#x47-460001.2.40 )
This is the way to go in C or C++ (#include "filename.h").
In Pascal it can be useful in some specific situation, you can find some 
examples in the source of the runtime library.
But the most natural way is to create one or several units : 
https://wiki.lazarus.freepascal.org/Unit
It's one of the strengths of Pascal which allow to compile faster than C.

There are two parts in the unit, interface and implementation.
You can move your procedure (procedure something( ...) ; begin end; ) 
from the main program to the implementation part and you need to repeat 
the first line of you procedure ( procedure something( ...) ; ) in the 
interface part.

Basically for using $i in a clean way you'll need to do a similar work, 
the content of the interface in a "filename.inc" file and the content of 
the implementation in a "filename.pp"  with a few other compilation 
directives, and adding the "filename.pp" to the linker.

It' easier to create a unit, the IDE can create a skeleton unit for you.
For using your new unit, instead of using $i, you'll just have to add it 
to the uses clause of your project.



More information about the Pas2js mailing list