[fpc-devel] Considerations about observer [was: Free Pascal 2.6.2 rc1]

michael.vancanneyt at wisa.be michael.vancanneyt at wisa.be
Wed Nov 28 09:14:19 CET 2012



On Tue, 27 Nov 2012, luiz americo pereira camara wrote:

> 2012/11/27 Michael Van Canneyt <michael at freepascal.org>:
>>
>>
>> On Tue, 27 Nov 2012, luiz americo pereira camara wrote:
>>
>>>
>>> Hi, i requested a change to observer interface with some
>>> considerations in http://bugs.freepascal.org/view.php?id=23394
>>
>>
>> It will not happen.
>>
>> If you want to pass around interfaces safely, then you need to implement
>> them as
>> descendents of IUnknown to maintain reference counts. They are implemented
>> as CORBA interfaces exactly to avoid the overhead of IUnknown.
>>
>> The consequence is that you must pass around the objects themselves.
>
> I don't see the point.
>
> It would be true if the IFPObserved (e.g., TPersistent) takes
> ownership of the attached observers. That is not the case.
>
> Currently, in the observer feature, there's no difference between
> plain TObject and corba interface (IFPObserver) regarding the life
> cycle management.

Correct.

>
> Both there are no guarantees that they will still be alive when accessed.
>
> The current approach limits the programmer flexibility and adds
> unnecessary overhead.
>
> As practical example take a LCL Form that is supposed to be observed.
> It takes an Observer property and attach it to certain child controls
> (TEdit etc)
>
> 1) Currently i'm forced to declare as the Observer property as an
> TObject. If i declare Observer property as IFPObserver i cannot attach
> to children controls.

I do not understand this ?

>
> 2) Each time i attach to a child control this Observer property will
> be queried to see if implements IFPObserver (but we already know that
> it implements, we already checked !!!)

You only gain speed when notifying. When calling FPOAttachAbserver or
FPODetachAbserver, you would need to typecast some object anyway if we 
would change the interface, so there is no speed gain there...

During notification, we can gain speed by internally storing the interface.

> So, i keep my points. Even because is not a big change with easy
> implementation that will fix the above issues.

It IS a big change. There is production code out there that uses this,
and this is an incompatible change.

I can change the internals so speed is gained during notifyobservers,
but I do not see sufficient reasons to change the interface and introduce an
incompatibility.

Michael.



More information about the fpc-devel mailing list