[fpc-devel] Recent added support for Observer pattern in FCL

michael.vancanneyt at wisa.be michael.vancanneyt at wisa.be
Tue Aug 28 14:15:35 CEST 2012



On Tue, 28 Aug 2012, Luiz Americo Pereira Camara wrote:

> Em 28/8/2012 04:50, michael.vancanneyt at wisa.be escreveu:
>> 
>> 
>> On Mon, 27 Aug 2012, Luiz Americo Pereira Camara wrote:
>> 
>>> I ask to change to a mechanism that could allow customizable operations 
>>> (more than one)
>> 
>> That is why you have ooCustom.
>> 
>>> 
>>> 
>>> I'm asking that because i have implemented a similar mechanism that 
>>> support operations like Load, ChildAdd, ChildDelete, ChildChange. I 
>>> believe that more developers are in the same situation,i.e., using 
>>> observer pattern to an action not handled by those 5 types. It would be 
>>> helpful to use the native implementation otherwise i will have to 
>>> keep(re-implement) the observer support over TPersistent.
>> 
>> That's why you have ooCustom and Data at your disposal.
>> 
>
> ooCustom is already used in TCollection if i remember correct.

In TList and TCollection. I will change it to ooDeleteItem; The effect is
the same. Extract and Delete are the same operation at the pointer level, 
after all.

> If i use it for a TCollection descendant that uses ooCustom with a record 
> pointer i would get a conflict and a possible crash.
>

A useful observation, and I will take it into account.

>
> Why not let TFPObservedOperation as integer and define constants.
>
> It could define a constant like ooUser = 32
> Below ooUser is reserved for future default constants
> Above ooUser could be added custom messages
> This is how LCL messages works

Exactly because it is not meant as a general messaging interface, 
and I want the interface to reflect this.

There is a clear intended use case: Mainly notification of changes.

In this sense, it is a unification and extension of the 
TStrings.Changed, 
TCollection.Notify and
TList.Notify 
which already were defined by Delphi (and which, for some strange reason,
have different interfaces).

The enumerated reflects the intended use cases:
Change notification, and for list-type objects, insertion and deletion of items.

If you want to go outside that, then this is possible too:
you can use ooCustom and Data.

I will make sure it is not used in standard notifications.
(see the change above)

Using the outlined use-cases I gave you can still define an extension with
an integer and put that in the object/record to use on ooCustom.

If someone has an idea about a general-purpose notification type then that can 
of course be discussed.

For example, on my 'doubtful' list I had "ooPropertyChange", to be used in 
combination with the GetPropInfo() and a call in TPersistent:

FPOPropertyChanged(Const APropName : String);

I'm still not 100 % sure what to do with that.

As for the preterit in ooChanged, I will look at it too.

Michael.



More information about the fpc-devel mailing list