[UP] Data types
|
The representation of the data types in O'Caml In the O'Caml environment, the dialog data types are represented as follows: type var_value = String_value of string | Enum_value of string list | Dialog_value of dialog_type option | Dyn_enum_value of (string * string) list | Alist_value of (string * var_value) list(You can find this in the module Wd_types.) This leads to the following value literals:
Getting values of variables Let dlg be the current dialog object in the following examples. In order to get a variable of arbitrary type one can invoke the variable method: let v = dlg # variable "name" in ...After that, v is a var_value (i.e. something like String_value, Enum_value etc.). - If you already know that the variable is a string, you can also call: let s = dlg # string_variable "name" in ...Now s is directly an O'Caml string (and not a String_value). - For the other types, there are direct accessor methods, too: let enum = dlg # enum_variable "name1" in ... let dyn_enum = dlg # dyn_enum_variable "name2" in ... let dlg' = dlg # dialog_variable "name3" in ...For associative lists, there are several possibilities to get values in a more convenient way. First, one can directly get the defining list: let alist = dlg # alist_variable "name" in ...Furthermore, it is possible to look up a component "key" of the list by one of the following invocations (depending on the base type): let s = dlg # lookup_string_variable "name" "key1" in ... let enum = dlg # lookup_enum_variable "name" "key2" in ... let dyn_enum = dlg # lookup_dyn_enum_variable "name" "key3" in ... let dlg' = dlg # lookup_dialog_variable "name" "key4" in ... Setting values of variables There is only one method to set a variable to a value v: dlg # set_variable "name" vConstructing a var_value from a base value is already very simple, such that there is no need for methods setting the base value directly. For example, if a variable must be set to a string s, the following elegant notation is possible: dlg # set_variable "name" (String_value s) Resetting values of variables There is another method that resets a variable to its initial value: dlg # unset_variable "name" The dot notation As a more convenient method to access variables of inner dialogs, it is possible to refer to variables by the dot notation. For example, if there is a dialog-type variable d, and the string variable s is defined within the dialog that is currently the value of d, you can get the string contents of s by this expression: let s = dlg # string_variable "d.s"This is a shorthand notation for: let s = match dlg # dialog_variable "d" with None -> failwith "Dialog variable is empty!" | Some d -> d # string_variable "s"See the section about Dot notation (v1.v2) for a broader discussion of this topic. |