[Lazarus] Package and project file format

Michalis Kamburelis michalis.kambi at gmail.com
Sat Mar 3 11:42:12 CET 2018


2018-03-03 11:15 GMT+01:00 Michael Van Canneyt via Lazarus
<lazarus at lists.lazarus-ide.org>:
>
> Hello,
>
> The package .lpk andproject .lpi file use the following format :
>
>     <Units Count="241">
>       <Unit0>
>         <Filename Value="lazarus.pp"/>
>         <IsPartOfProject Value="True"/>
>         <UnitName Value="Lazarus"/>
>       </Unit0>
>       <Unit1>
>         <Filename Value="frames/oi_options.pas"/>
>         <IsPartOfProject Value="True"/>
>         <ComponentName Value="OIOptionsFrame"/>
>         <HasResources Value="True"/>
>         <ResourceBaseClass Value="Frame"/>
>       </Unit1>
>
>
> And similarly
>      <RequiredPackages Count="7">
>       <Item1>
>         <PackageName Value="LazDebuggerGdbmi"/>
>       </Item1>
>       <Item2>
>         <PackageName Value="LCLBase"/>
>         <MinVersion Major="1" Release="1" Valid="True"/>
>       </Item2>
>
>
> Is it possible to get rid of the counts ?
>
> Reason: if 2 people add files to a package/project, it always creates
> conflicts when updating from the VCS. And if you're in bad luck, you need to
> change a lot of items.
>
> On the other hand, if you do
>      <RequiredPackages>
>       <Package name="LazDebuggerGdbmi"/>
>       <Package name="LCLBase">
>         <MinVersion Major="1" Release="1" Valid="True"/>
>       </Package>
>
> The chance of conflicts becomes less, and the resolution easier.
>

I am guessing the Count="xxx" attribute, and the numeric suffixes to
<Unit1> , <Item1> are there to read and write these files using
TXMLConfig class. Using TXMLConfig exposes an easy API to work with
XML files, but it limits what you can do --- all the children nodes
within the same parent must have a different name, so that you can do

File1 := XmlConfig.GetValue('Units /Unit1/FileName/Value');
File2 := XmlConfig.GetValue('Units /Unit2/FileName/Value'); ....

In Castle Game Engine, we added some extensions to TXMLConfig, in
particular TCastleConfig.PathElement to address exactly this. It
extracts a DOM element (TDOMElement) from TXMLConfig, and then you can
use full power of the DOM unit to operate on this element (iterate on
children etc.):
https://github.com/castle-engine/castle-engine/blob/master/src/files/castlexmlconfig.pas#L258
. This way you can still use TXMLConfig API (GetValue / SetValue) for
some tasks, but you can switch to using more powerful DOM API for
other tasks.

I thought maybe this is helpful :)

Regards,
Michalis


More information about the Lazarus mailing list