Yes I agree 100%, currently where you are at it does exactly what you want.
Not only that, it looks like you can also insert additional items using the same instance supplying
different sections not related to the FORM for example..
--
More digging, I find that not only does it have this problem but it also calls the Flush and FreeAndNil on a
DOC object that has not yet been created or the DOC variable initialize to Nil..
I am assuming the heap space for each instance of a Class does not auto-clear the memory to 0 ?
If this is the case then I can see this component and any one that inherits from it generating a random
Segfault or maybe just corrupting other parts of code..
In the constructor the inherited constructor is called which is Tcomponent, that takes care of reading the
Properties from file and assigning them. So the DoSetFIleName method gets called during this process and
a Flush, FreeAndNil(DOC) is done, However, the DOC member does not get set until the top constructor completes
, even the overridden method LOADED gets called which also then Sets the filename will hit the same wall
before the Top level constructor completes which is where the actual DOC is initially created.
constructor TXMLConfig.Create(AOwner: TComponent);
begin
inherited Create(AOwner); // This will call the DoSetFileName method for the filename string.
FRootName := 'CONFIG'; // This looks like it is overriding the property in the OI
Doc := TXMLDocument.Create;
Doc.AppendChild(Doc.CreateElement(FRootName));
end;
Maybe I don't understand the loading procedures of a component with published properties in Lazarus, I know
that is how they work in Delphi as I layout.
The Constructor in TComponent will do all the fancy stuff to assign the properties
Maybe the Inherited Create should be called at the end instead ?
Did I over look something here?
Nope: Scratch that last one, I forgot the ReadState is called well after..