[fpc-pascal] Implementing AggPas with PtcGraph

Tomas Hajny XHajT03 at hajny.biz
Thu Jun 15 14:34:10 CEST 2017

On Thu, June 15, 2017 13:57, James Richters wrote:
>>The idea is that you have one project per program. You can compile them
>> randomly without changing anything.
> I don't understand what you mean by 'one project per program' ?  I only
> have programs that I have sorted in sub directories.  I normally use the
> Freepascal text IDE to compile them, and sometimes the command line.   I
> might want to have ProgramA.pas have one define and ProgramB.pas have
> another, both using the same unit, is there some method to do that?


1) Have sources of the two programs in different folders (directories) and
start the text-mode IDE in the respective folder depending on the
"project" / program you intend to build.

2) Set the compiler defines as necessary for the respective "project"
(i.e. differently for ProgramA when started from directory of ProgramA and
for ProgramB when started from directory of ProgramB) - Options ->
Compiler -> Conditional defines. By default, the configuration is
automaticaly saved when exiting the IDE.

3) Make sure you always rebuild the unit depending on the program you want
to compile (Compile -> Build). Obviously, this requires the source file of
the unit to be available for the compiler (i.e. in one of paths in Options
-> Directories -> Unit directories).

>>There are already many ways to add defines. Adding another one would make
>> it harder for newbies.
> Is there some method to make a global define that is in the program
> itself?   I don't see how having options available makes anything harder
> for anyone, they can just not use such features.

The hard thing is for the user to understand differences among the
available options and their implications.

Defines have impact only when compiling the particular source code. Having
a 'global define' in a program could never have impact to a unit which
might be already compiled using different defines at the moment the
particular program is compiled. One of possible solutions for this is
having a 'global include file' which is included in all the relevant units
and the program, the other is outlined above (defines stored in the
compiler / IDE configuration file).

>>If you want a compiler define for all projects, then simply add that
>> define in your fpc.cfg file. That is a "global options" file. I trust
>> those will take effect even if you use the FPC Text IDE, because it is
>> the fpc.exe binary that reads the fpc.cfg file and gets default settings
>> from there.

Not quite - the text-mode IDE doesn't invoke fpc.exe binary (it has the
compiler built-in) and it passes the options as defined in the respective
IDE dialogs.

> Thanks for explaining that.  It looks like I can define where my units are
> with fpc.cfg as well and then I won't need to keep putting them on the
> command line.   If I put an fpc.cfg in a specific directory along with my
> program to be compiled, will the one in that directory override the one in
> \FPC\3.0.2\bin\i386-win32 ?

Yes (if starting the _compiler_ in that directory). If using the IDE, you
can do the same with the fp.cfg file.

> I'm wondering if I am missing something with reference to 'projects' is
> that a Lazarus thing?   How are 'projects' defined?

Yes, projects are 'a Lazarus thing'. However, you can achieve a similar
effect with local options and configuration files for the text-mode IDE
(you just need to use different directories for different 'projects').

Hope this helps


More information about the fpc-pascal mailing list