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

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to