Thanks Martin. I had not worked with eventhandlers added from code before and so had to experiment a bit before getting it to work. Some things learned:
1) In the call to eventHandler(), you do not need to mention whatever arguments the event handler method has
2) The method refered to does not necessarily need to be put in a class, it can be in a form as well
3) When added this way, the event handler method does not need to be prefixed with something like
[FormControlEventHandler(formControlStr(MyFormName, Fieldname), FormControlEventType::Clicked)]
that you usually get when using "copy event handler method" in the gui form designer
So finally some more fleshed out example code:
dynamic field creation in a form:
FormCheckBoxControl fc = groupcontrol.addControl(FormControlType::CheckBox, 'CheckboxName');
fc.Onclicked += eventhandler(element.CheckBox_OnClicked);
and the corresponding onclicked-method, which can be resused from multiple checkboxes:
public void CheckBox_OnClicked(FormControl sender, FormControlEventArgs e)
{
FormCheckBoxControl fc = sender as FormCheckBoxControl;
if (fc)
{
info(strFmt("Checkbox %1 set to %2", fc.name(), fc.value()));
}
}