[fpc-pascal] Externalization and inclusion of .PAS files (with GTK+) ?

Artur Stuczynski stootch at tlen.pl
Thu Feb 28 19:42:41 CET 2008


T. Guilleminot wites:

> So I'd like to deport most of my code (procedures, functions...) to these
> external .pas files and include them into the main.pas, a kind of
> "include"-like in PHP.
> (...)
> Does anyone able to provide me a simple example to achieve this ?
> Thanks for any answer.

Probably most elegant (though not fully equivalent to PHP) solution I've 
seen is in fpc's units:

unit main;

interface
uses ... {all units required by main.pas and included.pas in interace part}

{$undef read_implementation}
{$define read_interface}

{$i included.pas}

{$undef read_interface}

implementation
uses ... {all units required by main.pas and included.pas in 
implementation part}

{$define read_implementation}

{$i included.pas}

{$undef read_implementation}

begin
end.

...

unit included;

{$ifdef read_interface}
//interface part goes here
{$endif read_interface}

{$ifdef read_implementation}
//implementation part goes here
{$endif read_implementation}

Hope this helps.



More information about the fpc-pascal mailing list