[fpc-pascal] using functions from units & main programme

Bernd prof7bit at googlemail.com
Fri Nov 18 21:21:24 CET 2011


2011/11/18 John Lee <johnelee0 at gmail.com>:
> Never seen this before - is there a way I can force fnb to use the main
> program's version of fna, not the version that's in the unit?
> TIA John

Your problem sounds very much like you would really want to make use
of objects, inheritance and virtual methods. Instead of passing
procedure variables to modify or specialize the behavior of Jim.fnb
you would make Jim a class with virtual methods:

You could have a class TJim (declared in the unit jim) with two
methods fna and fnb and you would declare fna as a virtual method (so
it can later be overridden). In your main program you would declare a
class TFred derived from TJim and override fna. Then when you make an
instance of TFred and call Fred.fnb the code of fnb would
automatically use the fna method of TFred.

Bernd



More information about the fpc-pascal mailing list