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

Bernd prof7bit at googlemail.com
Sat Nov 19 18:42:04 CET 2011


2011/11/19 John Lee <johnelee0 at gmail.com>:
> Surprised this capability hasn't come up before because doesn't
> sound technically difficult to do.

The problem is simply that at the time of compiling the unit all the
function calls within it are already statically resolved and
everything is cast in concrete. Pascal is a static language. It does
NOT try to resolve each and every function call at runtime by looking
up their names to see which one matches under the current
circumstances like some highly dynamic languages do (at the cost of
speed), instead each function call is completely resolved at compile
time.

Of course sometimes (quite often) the need arises to replace certain
function calls within a library or a framework at a later time (decide
at runtime which function to call), this is known as late binding, for
this there is no other way than to either simply use a callback
function (a procedure variable (as the name implies: the procedure is
variable, not constant), this is the pragmatic simple C like approach
best suited for simple things) or do the same with inheritance and
overriding virtual methods (this is basically just another way of
solving the exact same problem: specializing the behavior of some
generic library code).

Bernd



More information about the fpc-pascal mailing list