[fpc-devel] Question on constref

Ondrej Pokorny lazarus at kluug.net
Thu Feb 2 10:17:29 CET 2023


On 02.02.2023 10:15, Michael Van Canneyt via fpc-devel wrote:
> On Thu, 2 Feb 2023, Ondrej Pokorny via fpc-devel wrote:
>> I myself cannot think of any real use case of constref other than 
>> hacks like the FreeAndNil in recent Delphi versions:
>>
>> procedure FreeAndNil(const [ref] Obj: TObject);
>>
>> that needs the ref because it changes it to nil (so is not really a 
>> const - it used to be an untyped var). As a result FreeAndNil allows 
>> you to happily pass read-only properties to it that are then nilled.
>
> Which is a clear violation of the concept of Const... :/

Exactly.

Ondrej



More information about the fpc-devel mailing list