[fpc-pascal] What's a unit?

ik idokan at gmail.com
Tue Feb 19 14:37:13 CET 2013


On Tue, Feb 19, 2013 at 3:31 PM, Mark Morgan Lloyd
<markMLl.fpc-pascal at telemetry.co.uk> wrote:
> Does a unit- rather than something it contains- have any sort of
> representation which is recognisably distinct from an object?
>
> I've got a situation where if a library (.dll or .so) is opened under
> program control it is represented by an object, with entry points expressed
> as methods. Alternatively, if it's statically linked then it's represented
> by a unit, with entry points represented by procedures and functions. That
> allows me to write things like
>
> caps := LibCapShim.cap_get_proc;  // LibCapShim is object or unit

It's a namespace. It can be a namespace of a unit, record, instance of
class or object.

> if caps <> nil then
>   try
>     caplist := capability;
>     r := LibCapShim.cap_set_flag(caps, flag, 1, @caplist, Ord(value));
>
> which is OK at the application level irrespective of how the program's
> built.
>
> What I can't do, without a conditional directive, is check whether the
> object representing the library is nil (because the dll/so isn't available).
> Instead I'm having to do
>
> {$ifdef USE_DYNAMIC_LIBCAP }
>   if LibCapShim = nil then      (* Initialisation failed        *)
>     exit;
> {$endif                    }
>   caps := LibCapShim.cap_get_proc;
>
> and so on. There's obviously ways around this, but they tend to rely on
> adding validity functions outside the object. Is there any way of doing
> something like
>
> if LibCapShim is TObject then
>   if LibCapShim = nil then      (* Initialisation failed        *)
>     exit;
>
> without the compiler objecting when it finds itself looking at a unit name
> in isolation?
>
> --
> Mark Morgan Lloyd
> markMLl .AT. telemetry.co .DOT. uk
>
> [Opinions above are the author's, not those of his employers or colleagues]
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal



More information about the fpc-pascal mailing list