[lazarus] fpc 1.9: global property

Marco van de Voort Marcov at stack.nl
Sat Dec 27 14:12:15 EST 2003


> > > 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;







More information about the Lazarus mailing list