Domain クラスで出来そうですね。
Code:
{let rs:RecordSet =
{RecordSet
{RecordFields
{RecordField
"First", caption = "First Name", domain = String
},
{RecordField
"Last", caption = "Last Name", domain = String
},
{RecordField
"Age", domain = int
},
{RecordField
"BD", domain = {BigDecimalDomain}
}
},
{RecordData First = "John", Last = "Smith", Age = 25, BD = {BigDecimal.from-String "0"}},
{RecordData First = "Jane", Last = "Smith", Age = 29},
{RecordData First = "Jane", Last = "Jones", Age = 28}
}
}
{define-proc public {set-record-data
val:any,
record:Record,
rf:RecordField
}:void
{if-non-null {rf.domain.validate val} then
||validate に成功したら、値をクリアする
{if rf.nullable? then
set record[rf.name] = null
else
set record[rf.name] = rf.default-value
}
else
||validate に成功したら、値をコンバートしてセット
set record[rf.name] = {rf.domain.convert val}
}
}
{def tf = {TextField}}
{def dl = {DropdownList }}
{for rf in rs.fields do
{dl.append rf.name}
}
{VBox {RecordGrid record-source = rs, height = 2in}, tf, dl}
{CommandButton
label = "指定フィールドに値をセット",
{on Action do
def val = tf.value
def rf = {rs.fields.get dl.value}
{for r in rs do
{set-record-data val, r, rf}
}
}
}