Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / pas2js / 2020-09

does {$i} directive work for pas2js

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mgr. Janusz Chmiel

Dear professional developers here. I have been intensively thinkink about my errors which I Am doing while writing code in Pascal. I have found out, that to avoid various issues while adding procedures in The right order. If my good way would not lead through {$i} directive and some .pas source which would contain main procedures such as adding audio support, creating GUI widgets. And my main .pas program which could call procedures and functions from other .pas source. Or do you think, that this approach will not be good idea?

I want to have A free hand when writing Pascal source which will react on events and which will contain many if then condition blocks. To avoid The situation, that I will have locked hands because. Audio widget procedure will relay 30 lines down after if then condition block which will make A decision which station will be plaied for example. But may be, that it is not good idea, since I can also god myself to some chaos.

Reply by email

Jean SUZINEAU
to Mgr. Janusz Chmiel

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.

Reply by email