[lazarus] fpc 1.9: global property

Mattias Gaertner nc-gaertnma at netcologne.de
Sat Dec 27 14:18:29 EST 2003


On Sat, 27 Dec 2003 19:03:05 +0100  "Marco van de Voort" <Marcov at stack.nl>
wrote:

> > > > Interesting feature.
> > > > Where can I find the specs?
> > >
> > >They are the same as normal properties, only without class. Read/write
> > >specifiers can be in another unit, and properties can be grouped as in
> > >var/const/type/resourcestring blocks.
> > >
> > >So something like:
> > >
> > >Unit SomeProps;
> > >
> > >Uses
> > >   ReadWriteUnit;
> > >
> > >Property
> > >   A1 : Integer Read GetA1 Write SetA1;
> > >   A2 : Integer Read GetA2 Write SetA2;
> > 
> > Cool :-)
> 
> The main idea is to keep code that depends on variables in an 
> external lib that are exported via function into variable notation.
> 
> E.g.  libc's errno (the problem in question) is exported by libc as a 
> function that returns a pointer to the (right threadinstance of ) errno. 
> Libc hides this with a macro.
> 
> So 
> 
> function __error():pcint; external name '__errno';  // FreeBSD libc, 
> Linux calls it errno_location
> 
> procedure seterrno(newerrno:cint);
> 
> begin
>   __error():=i;
> end;
> 
> function geterrno:cint;
> 
> begin
>   result:=__error();
> end;
> 
> property
>    errno : cint read geterrno write seterrno;
> 
> begin
>   errno:=5;		// behaves like when accessed in C, but threadsafe. 
>   writeln(errno);
> end;

:)

The codetools support it now.


Mattias








More information about the Lazarus mailing list