DocumentTools[Components] - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : Document Tools : Components : DocumentTools/Components/State

DocumentTools[Components]

  

State

  

generate XML for a State Component

 

Calling Sequence

Parameters

Description

Examples

Compatibility

Calling Sequence

State( stateName, field1, field2, ... )

Parameters

stateName

-

{assignable,string}; name to which the state is assigned

fieldN

-

:{name,name=anything}; (optional); your choice of Record field names

Description

• 

The State command in the Component Constructors package returns an XML function call which represents a "State Component".  A "State Component" is a virtual construct that holds a reference to a name.  When a State component is made active as part of a Worksheet instantiated with InsertContent, the name and its value are implicitly saved when the associated worksheet is saved.  The value and name are also restored automatically after restart.  

• 

The returned value is generated XML, which may be used with the results of commands in the Layout Constructors package to create an entire Worksheet or Document in XML form. Such a representation of a Worksheet or Document may be inserted into the current document using the InsertContent command.  

• 

The first argument is the global name of the state variable.  This must be either a string or unevaluated name.  A string tells the command what name to use, whereas an unevaluated name will cause a random unique name to be generated and assigned to that unevaluated name (as a pass-by-reference set value).  This state variable can then be passed to action handlers so they can process the action with entirely self-contained state.  This is important especially when the same component application can appear multiple times within the same worksheet.

• 

The remaining arguments are field names or field-name = value pairs.  If any field names are present, the stateName variable will be assigned to a Record containing those field names and values.

• 

The State command currently uses a hidden DataTable component as the mechanism for implementing this functionality.

Examples

Counter := module()
       local ModuleApply := proc(val)
               local xml, stateVar, stateXML;
               uses DocumentTools:-Layout, DocumentTools:-Components;
               stateXML := State('stateVar','data'=val,'xmap');
               
               xml :=  Worksheet( Table( Column(), Column(),
                               Row(
                                       Cell(TextArea(convert(val,string),identity="TextArea0")),
                                       Cell(Button("Increment",action=sprintf("Counter:-Increment(%s)",stateVar)),
                                           stateXML
                                       )
                               )));
               stateVar:-xmap := DocumentTools:-InsertContent(xml,output=table,'state'=convert(stateVar,string));
               NULL;
       end proc;

       export Increment := proc( sv )
               sv:-data := sv:-data + 1;
               DocumentTools:-SetProperty(sv:-xmap["TextArea0"],'value',sv:-data);
       end proc;
end module:

Counter(1);

Counter(10);

 

Compatibility

• 

The DocumentTools[Components][State] command was introduced in Maple 2016.

• 

For more information on Maple 2016 changes, see Updates in Maple 2016.

See Also

Component Code

Component Constructors

DocumentTools

Embedded Components

XMLTools