I am proposing to add a private FOwner: TPersistent; to TCollection and remove it from derived classes which already have it. At least TParams has it but it is not used. The next step would be to assign a proper owner for derived TCollection instances, case by case. Lazarus has code to go up in hierarchy by TPersistent.GetOwner calls. See: function GetLookupRootForComponent(APersistent: TPersistent): TPersistent; So, it already works perfectly if only the Owners are set.
My fundamental goal is to fix issue https://bugs.freepascal.org/view.php?id=25068 There is no link from a TCollection to its "owner" object which is called "LookupRoot" in Lazarus sources. The Collection is not visible in Object Inspector and changing a CollectionItem cannot mark the top-level Form/DataUnit as modified. Mattias has made a hack where the "LookupRoot" of certain TCollection derivatives can be queried. It was implemented for TFieldDefs with an explicit Dataset propery. In r56855 changed it to query TDefCollection which actually defines the Dataset and thus includes derived IndexDefs, too. Yes, now FieldDefs and IndexDefs both show in OI and changing them sets Modified flag correctly. But, it is still a hack and does not scale. We need a general solution for all TCollection derivatives. What more, the "Owner" of TDefCollection is not used which is poor design. It could be used instead of "Dataset". TParams has FOwner which is correctly returned by overridden method GetOwner. However it is never set which can be considered a bug. I tried to assign owner DataSource.DataSet for it in the only place of creation I found, but it has no effect. Function TCustomSQLStatement.CreateParams: TSQLDBParams; var DS: TDataSet; begin if Assigned(DataSource) then DS := DataSource.DataSet else DS := Nil; Result:=TSQLDBParams.Create(DS); end; TFPWebActions is another TCollection derivative without an owner. I am sure there are plenty more but I did not study them. I can provide a patch to add FOwner to TCollection and to return it by GetOwner but I don't know much about the derived classes in FPC libs. Help is needed there. One note: the TCollection.Owner explained here is not inherently tied to memory management like TComponent.Owner is. Juha _______________________________________________ fpc-devel maillist - [email protected] http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
