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.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to