Vcl2Xml (version 1.0)
XML format for Delphi VCL components
WSoft Lab Active GIF Creator Image Constructor Animate Me! WImageEditor XML References

Library Vcl2Xml is a tool to use XML format for objects from Delphi VCL classes. Attributes of elements are published properties in classes. Microsoft dynamic link library msxml.dll is used. So class TPersistent is used as base class for transformation to XML. Published property with type TBitmap or TPicture is stored as hexadecimal form of byte stream.
Freeware. DCU files for Delphi5.
Source: US$10.
Download: vcl2xml.zip (42K)

<view>
<panel align="alTop" alignment="taCenter" anchors="akLeft,akTop,akRight" autosize="False" bevelinner="bvNone" bevelouter="bvRaised" bevelwidth="1" bidimode="bdLeftToRight" borderstyle="bsNone" borderwidth="0" caption="" color="-2147483633" ctl3d="True" cursor="0" docksite="False" dragcursor="-12" dragkind="dkDrag" dragmode="dmManual" enabled="True" fullrepaint="True" height="131" helpcontext="0" hint="" left="0" locked="False" name="pnlView" parentbidimode="True" parentcolor="False" parentctl3d="True" parentfont="True" parentshowhint="True" showhint="False" taborder="1" tabstop="False" tag="0" top="0" usedockmanager="True" visible="True" width="249">
<constraints maxheight="0" maxwidth="0" minheight="0" minwidth="0"/>
<font charset="1" color="-2147483640" height="-11" name="MS Sans Serif" pitch="fpDefault" size="8" style=""/>
<label align="alTop" alignment="taCenter" anchors="akLeft,akTop,akRight" autosize="True" bidimode="bdLeftToRight" caption="XML format for VCL" color="-2147483633" cursor="0" dragcursor="-12" dragkind="dkDrag" dragmode="dmManual" enabled="True" height="20" hint="" layout="tlTop" left="1" name="lblOut" parentbidimode="True" parentcolor="True" parentfont="False" parentshowhint="True" showaccelchar="True" showhint="False" tag="0" top="1" transparent="False" visible="True" width="247" wordwrap="False">
<constraints maxheight="0" maxwidth="0" minheight="0" minwidth="0"/>
<font charset="1" color="8421376" height="-16" name="MS Sans Serif" pitch="fpDefault" size="12" style="fsBold,fsItalic"/>
</label>
<image align="alNone" anchors="akLeft,akTop" autosize="True" center="False" cursor="0" dragcursor="-12" dragkind="dkDrag" dragmode="dmManual" enabled="True" height="62" hint="" incrementaldisplay="False" left="20" name="Image1" parentshowhint="True" picture="066269746D6170424D..." showhint="False" stretch="False" tag="0" top="60" transparent="False" visible="True" width="54">
<constraints maxheight="0" maxwidth="0" minheight="0" minwidth="0"/>
</image>
<panel align="alNone" alignment="taCenter" anchors="akLeft,akTop" autosize="False" bevelinner="bvLowered" bevelouter="bvRaised" bevelwidth="1" bidimode="bdLeftToRight" borderstyle="bsNone" borderwidth="0" caption="Vcl2Xml" color="-2147483633" ctl3d="True" cursor="0" docksite="False" dragcursor="-12" dragkind="dkDrag" dragmode="dmManual" enabled="True" fullrepaint="True" height="91" helpcontext="0" hint="" left="90" locked="False" name="pnl" parentbidimode="True" parentcolor="False" parentctl3d="True" parentfont="False" parentshowhint="True" showhint="False" taborder="0" tabstop="False" tag="0" top="30" usedockmanager="True" visible="True" width="155">
<constraints maxheight="0" maxwidth="0" minheight="0" minwidth="0"/>
<font charset="1" color="-2147483640" height="-11" name="MS Sans Serif" pitch="fpDefault" size="8" style="fsBold"/>
<label align="alNone" alignment="taLeftJustify" anchors="akLeft,akTop" autosize="True" bidimode="bdLeftToRight" caption="http://www.wsoft-lab.com" color="-2147483633" cursor="0" dragcursor="-12" dragkind="dkDrag" dragmode="dmManual" enabled="True" height="13" hint="" layout="tlTop" left="10" name="lblIn1" parentbidimode="True" parentcolor="True" parentfont="False" parentshowhint="True" showaccelchar="True" showhint="False" tag="0" top="62" transparent="False" visible="True" width="123" wordwrap="False">
<constraints maxheight="0" maxwidth="0" minheight="0" minwidth="0"/>
<font charset="1" color="8388736" height="-11" name="MS Sans Serif" pitch="fpDefault" size="8" style="fsUnderline"/>
</label>
<label align="alNone" alignment="taLeftJustify" anchors="akLeft,akTop" autosize="True" bidimode="bdLeftToRight" caption="WSoft Lab" color="-2147483633" cursor="0" dragcursor="-12" dragkind="dkDrag" dragmode="dmManual" enabled="True" height="13" hint="" layout="tlTop" left="10" name="lblIn2" parentbidimode="True" parentcolor="True" parentfont="False" parentshowhint="True" showaccelchar="True" showhint="False" tag="0" top="10" transparent="False" visible="True" width="51" wordwrap="False">
<constraints maxheight="0" maxwidth="0" minheight="0" minwidth="0"/>
<font charset="1" color="32896" height="-11" name="MS Sans Serif" pitch="fpDefault" size="8" style=""/>
</label>
<image align="alNone" anchors="akLeft,akTop" autosize="True" center="False" cursor="0" dragcursor="-12" dragkind="dkDrag" dragmode="dmManual" enabled="True" height="32" hint="" incrementaldisplay="False" left="116" name="Image2" parentshowhint="True" picture="0469636F6E..." showhint="False" stretch="False" tag="0" top="4" transparent="False" visible="True" width="32">
<constraints maxheight="0" maxwidth="0" minheight="0" minwidth="0"/>
</image>
</panel>
<bitbtn anchors="akLeft,akTop" bidimode="bdLeftToRight" cancel="False" caption="&Cut" cursor="0" default="False" dragcursor="-12" dragkind="dkDrag" dragmode="dmManual" enabled="True" glyph="424D..." height="25" helpcontext="0" hint="" kind="bkCustom" layout="blGlyphLeft" left="8" margin="-1" modalresult="0" name="btButton" numglyphs="2" parentbidimode="True" parentfont="True" parentshowhint="True" showhint="False" spacing="4" style="bsAutoDetect" taborder="1" tabstop="True" tag="0" top="32" visible="True" width="75">
<constraints maxheight="0" maxwidth="0" minheight="0" minwidth="0"/>
<font charset="1" color="-2147483640" height="-11" name="MS Sans Serif" pitch="fpDefault" size="8" style=""/>
</bitbtn>
</panel>
</view>

Unit Vcl2Xml

var TypePrefix: string = 't'; // lower case!
   XML element tags for classes beginning with TypePrefix do not contain prefix TypePrefix.

var RootElementTag: string = 'view';
   Name of root XML element in document for Vcl2Xml.

function PersistentToXMLDomElement(NodeName: string; Doc: TdomDocument; Persistent: TPersistent): IXMLDomElement;
  Create XML element from Delphi object.
    NodeName - node name, if empty ('') then class name is used (see also note about variable TypePrefix). This parameter defines element tag for subclass (for example, font in TPanel). It is impossible to use the subclass type name as two or more properties of the same type may be located in a class.
    Doc - XML document;
    Peristent - source Delphi object;
    Result - new XML element or nil if fails.

procedure XMLAttributesToPersistent(Element: IXMLDomElement; Persistent: TPersistent);
  Assign attributes from XML element to Delphi object.
    Element - XML element;
    Peristent - Delphi object.

function XMLDomElementToPersistent(Element: IXMLDomElement; Owner: TComponent): TPersistent;
  Create Delphi object from XML element.
    Element - source XML element;
    Owner - owner for component constructor;
    Result - new Delphi object or nil if fails.

procedure ComponentToDomDocument(Doc: TdomDocument; Component: TComponent);
  Create XML document for component. Element corresponding to source component is attached as child to root element of document. Note: component may include other components.
    Doc - XML document;
    Component - source component.

procedure DomDocumentToComponent(Doc: TdomDocument; RootComponent: TComponent);
  Create component from XML document. Note: component may include other components.
    Doc - XML document;
    RootComponent - component with some attributes and as a container for other components; XML element corresponding to RootComponent is attached as child to root element of document.

procedure WinControlToDomDocument(Doc: TdomDocument; WinControl: TWinControl);
  Create XML document for WinControl. Element corresponding to source WinControl is attached as child to root element of document. Note: WinControl may include other WinControls.
    Doc - XML document;
    WinControl - source WinControl.

procedure DomDocumentToWinControl(Doc: TdomDocument; RootWinControl: TWinControl);
  Create WinControl from XML document. Note: WinControl may include other WinControls.
    Doc - XML document;
    RootWinControl - WinControl with some attributes and as a container for other WinControls; XML element corresponding to RootWinControl is attached as child to root element of document.

Unit PFactory

Loading of Delphi objects from XML document demands object factory to produce objects with given type.
Current realization of this factory is very simple - you must modify function CreatePersistent:

  1. add string like:
    if ElementTag = 'myclass' then Result := TMyClass.Create;
  2. add necessary units in uses statement.
function CreatePersistent (ElementTag: string; Owner: TComponent): TPersistent;
  Class factory for TPersistent objects.
    ElementTag - tag of XML element;
    Owner - owner for component constructor;
    Result - new TPersistent object.

Unit MSXML_TLB

You need Microsoft dynamic link library msxml.dll. You can use the version already installed on your PC in Windows system or get new file from Microsoft site ( see: http://msdn.microsoft.com/xml/ ).
Pascal declarations in a MSXML_TLB.PAS file let you use these types as though they were native VCL objects. To generate this unit use Delphi command Project/Import Type Library. The Import Type Library dialog box displays the type libraries registered on your system so you can add them to your projects. Click Install or Create Unit button (see Delphi help).

WSoft Lab Active GIF Creator Image Constructor Animate Me! WImageEditor XML References
Home Copyright ©2000-2007 Image Tools Group
http://www.wsoft-lab.com