2.3 :apply()

There are two different forms of the :apply() method:

2.3.1 :apply() (Datamodel)

When calling this method on a View component, all data values of View attributes that are linked to Model components are read ( using a :retrieve() call) and assigned to the corresponding Model components.

By specifying the optional parameters, the restriction to a special view attribute or to a special indexed single value is possible. Without parameters :apply() will also be invoked on all children and their children.

Normally calling this method should not be necessary because synchronization between View and Model is controlled through the .dataoptions[] attribute.

Linkage to the Model component must have been established with the attributes .datamodel and .dataset.

There will be no error message if the object has no linked attributes or the optionally specified attribute does not exist or is not linked.

Definition

void :apply
(
  { attribute Attribute input { , anyvalue  Index input } } |
  { anyvalue  Index     input }
)

Parameters

attribute Attribute input
This optional parameter specifies the View attribute to be retrieved and assigned to the corresponding Model component.
anyvalue Index input
This optional parameter specifies the index value to be used for getting the value from the View object.

Example

In the following example dialog, the content string is assigned to the Data Model using the :apply() method on the edittext or on the window. The statictext at the bottom of the window shows the current value of the Data Model VarString.

dialog D
accelerator AcF5 "F5";
variable string VarString := "Friday";

window Wi
{
  .title ":apply demo";
  .width 200;

  child edittext Et
  {
    .xauto 0;
    .xright 80;
    .datamodel VarString;
    .dataset .value;
    .content "Saturday";
    .toolhelp "Press F5 to apply";
    
    on key AcF5
    {
      this:apply(.content);
    }
  }

  child pushbutton Pb
  {
    .xauto -1;
    .width 80;
    .text "Apply";

    on select
    {
      this.window:apply();
    }
  }

  child statictext St
  {
    .xauto 0;
    .yauto -1;
    .datamodel VarString;
    .dataget .value;
  }

  on close { exit(); }
}

2.3.2 :apply() (transformer)

With this method the transformation of data is triggered at a transformer object. Please refer to chapter “The transformer Object” of manual “XML Interface” for further details.

The method can be redefined (similar to :init()).

Definition

boolean :apply
(
      anyvalue Src  input
  { , anyvalue Dest input output }
)

Parameters

anyvalue Src input

In this parameter the root node is transferred from which the transformation starts. The default implementation differentiates between two cases:

  • If Src is a document object, the root of the XML tree, which represents the document, is taken as start node. The document must be loaded.

    If Src is a doccursor object, the node in the XML tree to which the doccursor points is taken as root node.

    The transformation is carried out from XML to IDM.

  • If Src is an IDM object (except for document and doccursor), this object itself is taken as root.

    The transformation is carried out to user-defined IDM data.

anyvalue Dest input output
This optional parameter is simply passed on to the :action() methods of the mapping objects. This means that within the method, :action(Next_Node, Dest) is invoked iteratively for each visited node.

Return value

The method returns true if the transformation was successful, false otherwise.

Objects with this method

transformer