[fpc-pascal] detect implementation / interface sections

Mark Morgan Lloyd markMLl.fpc-pascal at telemetry.co.uk
Fri Sep 25 10:44:56 CEST 2015


David Emerson wrote:
> I tried sending this message two days ago, but it seems not to have gone 
> through. Trying again.
> 
> I like using include files, to break up big units into multiple files, 
> and also as macro-based templates.
> 
> One thing I do frequently is to put both the interface and the 
> implementation into one include file, and include it twice-- once in the 
> interface, and once in the implementation section of the unit. The 
> include file thus looks like this:
> 
> {$ifdef interface}
>   <type declarations>
> {$endif}
> 
> {$ifdef implementation}
>   <code>
> {$endif}
> 
> 
> So my question-- right now I have to manually define and undefine the 
> symbols "interface" and "implementation" in each unit.
> 
> Is there a way to detect what section of a unit the compiler is in, 
> rather than using these user-defined symbols?
> 
> So in my include file(s), instead of writing {$ifdef interface} I would 
> write something that actually knows if an interface or implementation is 
> being compiled.
> 
> Ditto for initialization, finalization (although I use this much less 
> frequently)

I do something similar, but the problem is that every developer has his 
own idea of just how much detail is needed and in how many contexts a 
single file can be imported.

-- 
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]



More information about the fpc-pascal mailing list