[fpc-devel] Tests of observer feature [was: Considerations about observer]
Graeme Geldenhuys
graeme at geldenhuys.co.uk
Thu Nov 29 12:16:59 CET 2012
Hi Luiz,
First off, thanks for take the trouble it creating test projects.
On 2012-11-29 02:59, luiz americo pereira camara wrote:
>
> Test1
> As is today, if you have a reference to a IFPObserver is not possible
> to use it to attach to, e.g., child objects. This occurs because AFAIK
> you can't get a TObject from a interface reference.
OK, there are quite a few things I consider wrong with your Test1
application.
1) Nothing stops Michael from extending the IPFObserver interface to
include a GetObject function that returns a TObject reference of
the observer.
I have seen many such cases in the wild. Not sure if I agree
with it, but that is another story.
2) What exactly are you observing in Test1? What are you trying to
accomplish?
TMyParentView is a TObject. Adding children to the Children property
doesn't notify the observer about anything.
... now if the Observer property is holding reference to something
that should observer each of the Children, well, then that is very
easy to accomplish too. Simply changes the Observer property to
a TObject instance.
3) Something Michael should fix. TFPObjectList doesn't support
IPFObserver. TObjectList does though. I guess many of the list
classes in the Contnrs unit should be double checked.
4) If you change FChildren to TObjectList, then it can be observer.
Then simply attach observers directly to the Children property. That
way if you add or remove children, the observers are notified.
5) I guess this depends on what you want to accomplish. But if you
first add children, then only call Initialize, then the observer
will never be notified that children was added to the list.
It was actually hard to figure out what you are trying to accomplish
with your test project. I think I'm still unclear of this. I'm seriously
under the weather at the moment (bad case of flu), so that probably
affects my judgement. So if I misinterpreted your Test project, please
do let me know. In the mean time, I modified your test1 (see attached).
The Observer now observes the Children List, and each Child - again, not
100% sure what you wanted to accomplish.
So solving your supposedly "impossible" problem was rather easy. So I'm
still on Michael's side that the FPC Observer API needs no change.
Regards,
- Graeme -
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ObserverTest1.pas
Type: text/x-pascal
Size: 2396 bytes
Desc: not available
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20121129/00452160/attachment.pas>
More information about the fpc-devel
mailing list