[fpc-pascal] readonly variables

Mattias Gaertner nc-gaertnma at netcologne.de
Sat Nov 28 15:07:42 CET 2009


On Sat, 28 Nov 2009 14:58:26 +0100
J├╝rgen Hestermann <juergen.hestermann at gmx.de> wrote:

> > is it possible to set a variable in a programm as a readonly variable?
> 
> Not that I am aware of. But for what reason do you want such a behaviour? 
> 
> And if I think it over, this can only work at runtime (letting the program crash on the second assignment). At compile time the compiler may not exactly know which assignment is done in what order. If you set the variable in a procedure or function the compiler would have to check when this procedure is called (which can be called by another procedure and so on). The first call (and assignment) would be ok but the second should generate an error? How should the compiler know how often the routine is called? This can even be dependend on input data.

Same under bash.

Use the following:

property MyVar: integer read FMyVar write SetMyVar;

And in SetMyVar you can set flag and raise an exception if set for the
second time.

Mattias



More information about the fpc-pascal mailing list