Resources | Resources |



Value model

IValueModel inherits from the IModel interface and is the most basic model. It stores data that can be represented in an arbitrarily complex form, from simple text or integer or to a complex data structure.

For example, a thermometer that measures temperature in absolute values could be modeled using IValueModel to represent degrees Fahrenheit or Celsius as a simple integer. A more complex illustration of a value model could be a record extracted from a company database. The record might include fields for an employee's name, office number, extension, or even a bitmapped photo. In this case, the value model would store an entire data structure.

The interface provides object reference counting mechanisms that allow objects to manage their own memory instances. In addition, the interface provides functions for registering a listener with a value model, and for manipulating the data represented by the model. Value model notifications can be used to implement custom widgets that display content based on more complicated value information.

Using a value model

The following example demonstrates how to use IValueModel to update an Email Refresh Rate box value. This example assumes that a listener function, myapp_SliderValueListen(), has been created.

// Create the slider widget to which the model listener will be attached
nErr = ISHELL_CreateInstance(pMe->m_pIShell, AEECLSID_CSliderWidget, 

// Create a text widget that will display the current user data
if (AEE_SUCCESS == nErr) {
   nErr = ISHELL_CreateInstance(pMe->m_pIShell, AEECLSID_CTextWidget, 

/* Add piwCounterBox text label and insert into prop container */

// Create a model listener and initialize it with a listener function and user data
if (AEE_SUCCESS == nErr) {
   LISTENER_Init(pModelListener, myapp_SliderValueListen, pCounterBoxWgt);

   // Get the value model for the slider widget and attach it to the slider’s model
   if (AEE_SUCCESS == IWidget_GetModel(pSliderWgt, AEEIID_IValueModel, &pValueMdl)) {
      nErr = IModel_AddListener(pValueMdl, pModelListener);