Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2016-04

TPersistent does not call IFPObserved.FPONotifyObservers

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Dennis

I have a class inheriting from Tpersistent:
type
TCondition=class( TPersistent, ICondition)

var
   aCondition : TCondition;
  but surprisingly,  when I call
   aCondition.FPOAttachObserver(someobj);

I discovered that nothing was executed.
I used debugger to step through this line and nothing was executed.

As a result, when this aCondition is destroyed, it won't notify the observers.

I checked the source code "persist.inc", it is indeed implemented!

procedure TPersistent.FPOAttachObserver(AObserver: TObject);
Var
    I : IFPObserver;
begin
    If Not AObserver.GetInterface(SGUIDObserver,I) then
      Raise EObserver.CreateFmt(SErrNotObserver,[AObserver.ClassName]);
    If not Assigned(FObservers) then
      FObservers:=TFPList.Create;
    FObservers.Add(I);
end;

What is wrong? I am using FPC 3.1.1 trunk downloaded a few days ago.

From the documentation, there is this line:

TPersistent implements the IFPObserved
<http://www.freepascal.org/docs-html/rtl/classes/ifpobserved.html> interface for the benefit of descendent classes, but does not call IFPObserved.FPONotifyObservers
<http://www.freepascal.org/docs-html/rtl/classes/ifpobserved.fponotifyobservers.html>. Descendents such as TStrings
<http://www.freepascal.org/docs-html/rtl/classes/tstrings.html> and TCollection
<http://www.freepascal.org/docs-html/rtl/classes/tcollection.html> and TCollectionItem
<http://www.freepascal.org/docs-html/rtl/classes/tcollectionitem.html> do use it.

But the source code DOES CALL IFPObserved.FPONotifyObservers <http://www.freepascal.org/docs-html/rtl/classes/ifpobserved.fponotifyobservers.html>!

destructor TPersistent.Destroy;
begin
   If Assigned(FObservers) then
     begin
     FPONotifyObservers(Self,ooFree,Nil);
     FreeAndNil(FObservers);
     end;
   inherited Destroy;
end;

Why did the documentation say that? Why was those code seemed not linked at all? Some compiler options I messed up?

Dennis

Reply by email