[fpc-pascal] FPC PasCocoa/Differences

Jonas Maebe jonas at freepascal.org
Sat Mar 27 19:19:19 CET 2021


On 27/03/2021 19:11, Adriaan van Os via fpc-pascal wrote:
>     "The only way to add a traditional property—backed by a new instance
> variable—to an existing class is to use a class extension, as described
> in Class Extensions Extend the Internal Implementation."
> 
> So, the FPC PasCocoa/Differences wiki seems to ignore a crucial
> difference between ObjC categories and ObjC class extensions, namely the
> ability to add properties to an existing class.

I'm not sure that was already possible when that wiki page was written.
It was probably only added later in Objective-C 2.0.

> Am I correct that the latter is not possible in Objective-Pascal ?

You are correct. OTOH, it feels kind of useless in general, because

"A class extension bears some similarity to a category, but it can only
be added to a class for which you have the source code at compile time
(the class is compiled at the same time as the class extension)."

So there's not really much difference between a class extension with
fields and adding private fields to the class declaration itself. It's
more something to keep information completely out of the header files in
Objective-C. While you can use include files to separate your header and
implementation of a unit in Pascal, and then only distribute the header
include files so people can look at them, this feels like a rather niche
use case.


Jonas


More information about the fpc-pascal mailing list