[fpc-pascal] Read-only global references

Marcos Douglas md at delfire.net
Sun Mar 6 16:11:05 CET 2011


On Sun, Mar 6, 2011 at 6:14 AM, Mark Morgan Lloyd
<markMLl.fpc-pascal at telemetry.co.uk> wrote:
> Marcos Douglas wrote:
>
>>>> Make a function to return a global variable does not make it read only.
>>>> If I use your function like this:
>>>> o := InitText;
>>>> o := nil;  //this is the same xInitText = nil
>>>
>>> Disagree. You are changing the value of o, not of xInitText. xInitText is
>>> initialised once somewhere in the unit exporting it, subsequently its
>>> properties etc. can be used elsewhere e.g. InitText.AppendFormatted(...).
>>
>> I was right.
>> The "o" points to "xInitText". If you release "o" the "xInitText" will
>> be release too.
>> But if you do:
>> o:=nil
>> ...isn't the same xInitText:=nil, of course.
>
> You're right if you're talking about primitive heap operations, in exactly
> the same way that you'd be right if you used assembler to trample all over
> flat memory. However sticking to my original question which dealt with
> exporting an instance of an object, you could free the read-only object by
> doing o.Free which is identical to InitText.Free, i.e. you'd be using the
> declared destructor- which presumably could be hidden from calls outside the
> exporting unit.

I extrapoled your question... sorry.
But my initial concept is OK: your "read only" object is not read only.


Marcos Douglas



More information about the fpc-pascal mailing list