[fpc-devel] LocalReferenceFixup

José Mejuto joshyfun at gmail.com
Tue Oct 5 13:55:53 CEST 2010


Hello FPC,

Tuesday, October 5, 2010, 1:10:43 PM, you wrote:

>> I do not have too much experience with components, but calling
>> "Loaded" several times does not look very fine.
MVC> To the best of my knowledge: it should be called once only, after the fixups.
MVC> If it isn't so, this is a bug.

Extracted from "reader.inc", comments below...

------------------------------------------------------
[...]
procedure TReader.FixupReferences;
var
  i: Integer;
begin
  DoFixupReferences;
  GlobalFixupReferences;
  for i := 0 to FLoaded.Count - 1 do
    TComponent(FLoaded[I]).Loaded;
end;
[...]

function TReader.ReadRootComponent(ARoot: TComponent): TComponent;
[...]
      if Assigned(GlobalLoaded) then
        FLoaded := GlobalLoaded
      else
        FLoaded := TFpList.Create;

      try
        if FLoaded.IndexOf(FRoot) < 0 then
          FLoaded.Add(FRoot);
        FOwner := FRoot;
        FRoot.FComponentState := FRoot.FComponentState + [csLoading, csReading];
        FRoot.ReadState(Self);
        Exclude(FRoot.FComponentState, csReading);

        if not Assigned(GlobalLoaded) then begin
          for i := 0 to FLoaded.Count - 1 do
            TComponent(FLoaded[i]).Loaded;//----------------------------
        end;

      finally
        if not Assigned(GlobalLoaded) then
          FLoaded.Free;
        FLoaded := nil;
      end;
      GlobalFixupReferences;
[...]
end;

procedure TReader.ReadData(Instance: TComponent);
[...]
  { Fixup references if necessary (normally only if this is the root) }
  If (Instance=FRoot) then
    DoFixupReferences;
end;
[...]
------------------------------------------------------

As you can see the "Loaded" event is called (marked with some //-----)
before calling "GlobalFixupReferences", I'll try to add some writeln's
here and there to catch the event sequence and post it here for
further comments.

-- 
Best regards,
 José




More information about the fpc-devel mailing list