Sign in Join

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

Mailing lists / fpc-pascal / 2015-09

detect implementation / interface sections

3 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

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

David Emerson

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)

Thanks!

~David.

Reply by email

Mark Morgan Lloyd
to David Emerson
David Emerson wrote 32 lines
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]

Reply by email