3.81 DM_ValueInit
With this function a value reference can be converted into a local or global value reference managed by the IDM. This allows the further manipulation of the value by DM_Value…() functions and its transfer as parameter or return value.
The value reference is initialized with the appropriate type. The collection data types DT_list, DT_vector, DT_hash, DT_matrix and DT_refvec are also permitted.
If the value reference is initialized as static or global via the DMF_StaticValueoption, access is also possible outside the function call. Value lists and strings are not released at the end of the function. The initialization of arguments as static or global managed value references is not allowed.
String values are initialized with the NULL pointer. Collections are created without element values. All other value types are also initialized with a 0 value.
The function DM_ValueChange can be used to add or change values or part values respectively elements. A reinitialization using DM_ValueInit() is also possible.
DM_Boolean DML_default DM_EXPORT DM_ValueInit
(
DM_Value *value,
DM_Type type,
DM_Value *count,
DM_Options options
)
Parameters
-> DM_Value *value
This is the value reference to be initialized.
-> DM_Type type
This parameter specifies the requested initial type.
-> DM_Value *count
In this parameter the initial size of collections like list or matrix can be specified or the appropriate value type for vector values.
-> DM_Options options
Option |
Meaning |
---|---|
0 |
The value reference will be initialized as a local value. |
DMF_StaticValue |
The value reference will be initialized as a global, static value. |
Return value
DM_TRUE |
The function has been completed successfully so the value reference is initialized. |
DM_FALSE |
The value reference could not be initialized. |
Example
dialog Dialog function void AppendToList(anyvalue List input output, anyvalue Value); function anyvalue FindMinMax(anyvalue IntegerList); function string ListToString(anyvalue List); function void SetElemSep(string Sep); on dialog start { variable vector[string] WeekDays:=["Mo","Tu","Wed","Thu","Fri","Sat"]; variable list DaysPerWeek := [31,30,28,27]; SetElemSep(" , "); AppendToList(WeekDays,"Sun"); print ListToString(WeekDays); print FindMinMax(DaysPerWeek); exit(); }
... static DM_String elemSep = NULL; void DML_default DM_ENTRY SetElemSep(DM_String sep) { DM_StringInit(&elemSep, DMF_StaticValue); DM_StringChange(&elemSep, sep, 0); } DM_Value* DML_default DM_ENTRY FindMinMax(DM_Value *IntegerList) { DM_Value subval, minMaxList; /* managed local values */ DM_UInt count; DM_UInt minValueCount=0, maxValueCount=0; DM_Value index, mindex, data; /* unmanaged values */ /* initialize local managed values */ DM_ValueInit(&subval, DT_void, NULL, 0); DM_ValueInit(&minMaxList, DT_list, NULL, 0); /* determine the itemcount of the list */ count = DM_ValueCount(IntegerList, NULL, 0); index.type = DT_integer; index.value.integer = 1; while(count>0) { /* loop through the index 1,2,3,... */ if (DM_ValueGet(IntegerList, &index, &subval, 0) && subval.type == DT_integer) { if (minValueCount==0 || subval.value.integer<minValue) { minValueCount++; /* store maximum value at [1] in minMaxList */ mindex.type = DT_integer; mindex.value.integer = 1; DM_ValueChange(&minMaxList, &mindex, &subval, 0); } if (maxValueCount==0 || subval.value.integer>maxValue) { maxValueCount++; /* store maximum value at [2] in minMaxList */ mindex.type = DT_integer; mindex.value.integer = 2; DM_ValueChange(&minMaxList, &mindex, &subval, 0); } } count--; index.value.integer++; } /* return the minMaxList (without compiler warnings) */ return DM_ValueReturn(&minMaxList, 0); } ... void DML_default DM_ENTRY AppendToList(DM_Value *List, DM_Value *Value) { DM_Value newList; /* demonstrate the returning of a list-value by two ways * / if (List->type == DT_list || List->type == DT_vector) { /* 1) returning a manipulated argument (auto-management) */ DM_ValueChange(List, NULL, Value, DMF_AppendValue); } else { /* 2) creation of a managed local list-value */ DM_ValueInit(&newList, DT_list, NULL, 0); DM_ValueChange(&newList, NULL, List, DMF_AppendValue); DM_ValueChange(&newList, NULL, Value, DMF_AppendValue); *List = newList; } } DM_String DML_default DM_ENTRY ListToString(DM_Value *List) { DM_Value index; DM_Value value; DM_UInt count; DM_String retString; /* initialize the managed values */ DM_ValueInit(&index, DT_void, NULL, 0); DM_ValueInit(&value, DT_void, NULL, 0); DM_StringInit(&retString, 0); count = DM_ValueCount(List, NULL, 0); while(count>0) { if (DM_ValueIndex(List, count--, &index, 0) && DM_ValueGet(List, &index, &value, 0) && value.type == DT_string) { DM_StringChange(&retString, value.value.string, DMF_AppendValue); if (count>0) DM_StringChange(&retString, elemSep, DMF_AppendValue); } } return DM_StringReturn(retString, 0); }
Availability