[fpc-pascal] Merging units

Marco van de Voort fpc at pascalprogramming.org
Fri Oct 2 22:31:03 CEST 2020


Op 2020-10-02 om 19:55 schreef Ryan Joseph via fpc-pascal:
> Something that's bothered me for a while I wanted to ask about.
>
> I have a package I want to distribute which has 2 or more units, all of which are required to use the package. Technically all the code should be in one file but because units are a nice feature of Pascal we like to keep our code separate when we develop.
>
> Usually what happens is we compromise and do either:
>
> 1) Have the user of the package add all the units to the uses clause of every file which needs it. This is annoying for the user because it bloats the uses section but for the developer our code is nicely separated into units.
>
> 2) Break the units into include files and wrap the interface/implementation blocks in ifdefs. This is nice for the user because they only have a single unit to use but now the developers of the package have to work in what are essentially header files (like in C). The RTL is of course filled with examples like this.

In some cases you can also move types and consts to a secondary unit, 
but alias them in the primary one.

Like e.g. Unixtype (what unit you say? Never heard of it? That is 
because the types are aliased into core units baseunix and unix)


More information about the fpc-pascal mailing list