[fpc-devel] Recent added support for Observer pattern in FCL
Luiz Americo Pereira Camara
luizmed at oi.com.br
Tue Aug 28 03:48:22 CEST 2012
Back in 2010, in the thread about observer support in fcl, i asked if the actions would be customizable so i could, e.g., notify/observe if a child was added or removed in a tree structure. The answer was yes.
Looking at the recent added support, it limit the actions (called operations) to 5 types
TFPObservedOperation = (ooChanged,ooFree,ooAddItem,ooDeleteItem,ooCustom);
I ask to change to a mechanism that could allow customizable operations (more than one)
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.
The names of the TFPObservedOperation are not consistent:
ooChanged is in preterit while others not
ooChanged does not has Item suffix
it should be
The changes: http://svn.freepascal.org/cgi-bin/viewvc.cgi?view=rev&revision=22257
See the cited email:
Michael Van Canneyt escreveu:
> On Thu, 20 May 2010, Florian Klaempfl wrote:
>> I've no opinion if it's usefull to add or not, I use TPersistent+ too
>> little but my concern is: if I create an observer for an instance, I'd
>> expect to get notified about every change to the instance. But I cannot
>> see how this will be achieved, no existing class is prepared for this?
> Not every change. What you get notified about is defined by the class
> that uses the observable interface. TStrings will notify you of
> additions/removals, and TList/TObjectList as well.
It will send some kind of info (like index or address of the object) to
know what and where the item was added or removed?
> Can the same Obsever observe (:-D) more than of one type of object? e.g.
> i want to observe a object list for adding or removals, but also want to
> know if one of the child objects changed.
Yes. You can observe any object that will implement the IFPObservable
More information about the fpc-devel