Use/Syntax of the DOM-API in Embarcadero RAD Studio C++ Builder

If the FireDAC VCL component is used in Embarcadero RAD Studio with the C++ Builder - see also Using the VCL FireDAC component in C++ Builder Projects - there are the following points to consider when working with the DOM-API:

  • To ensure that the *.hpp file required for DOM access is also created within the List & Label component, it must first be added via the Embarcadero RAD Studio. To do this, load the ListLabel[xx]Components.dproj project from the Components directory ..\Samples\Delphi\FireDAC\Components\ and add the L[xx]dom.pas file and save it. Then proceed according to the instructions in the article Using VCL FireDAC Components in C++ Builder Projects.

  • To reference a project via DOM, it is necessary to pass the List & Label object in the constructor. This must be passed as follows:

    TLlDOMProjectList* proj = 
       new TLlDOMProjectList((L[xx]commoninterfaces::ILlDomParent*)*ListLabel);
  • Access to individual elements in various DOM lists such as TLlDOMLayerList, TLlDOMLayerList etc. cannot be taken 1:1 from the Delphi code, since the array/index operator for lists operator[] requires an adapted syntax in C++ Builder, since the C++ Builder, in contrast to Delphi, does not support “default” array properties.

    Either one prefixes the name of the property:
    UnicodeString sLayerName = proj->Layers->Items[0]->Name;

    Or one performs an explicit dereferencing of the list:
    UnicodeString sLayerName = (*proj->Layers)[0]->Name;

This is what a code snippet would look like in the C++ Builder to open a list project using the DOM-API, retrieve the name of the first layer and set the printer name for the first layout region:

...
UnicodeString projectFile = "<MyProjectFileName>";

// open an existing project file
TLlDOMProjectList* proj = 
    new TLlDOMProjectList((L[xx]commoninterfaces::ILlDomParent*)*ListLabel);
proj->Open(projectFile, TLlDOMFileMode::fmOpen, TLlDomAccessMode::amReadWrite);

// set the printer name for the first region - using 
// explicit dereferencing for element access
(*proj->Regions)[0]->Device->Name = "\"<MyPrinterName>\"";

// get the first layer name - using 
// the property name for element access
UnicodeString sLayerName = proj->Layers->Items[0]->Name;

// save and close project
proj->Save(projectFile);
proj->Close();
...