So I added a check box to my form. I am setting it's default state based on whether or not the buffer is empty. I don't want to do this in the form's on_create() event handler, primarily because an additional function seemed unnecessary. This works exactly as I want it too. However, I don't really understand it. The type system has me confused. Can anyone help me unpack this?
_form frm_uvm_class_wizard {
// ...
_check_box cInsertHeader {
// ...
}
}
void uvm_class_wizard() {
_control cInsertHeader;
int ed = _mdi.p_child;
int line = ed.p_line; // save location, because I don't really want the cursor to move
int col = ed.p_col;
frm = show("frm_uvm_class_wizard");
frm.cInsertHeader.p_value = _mdi.p_child.find('\S','LIHP@') ? 1 : 0;
ed.p_line = line; // restore location
ed.p_col = col;
}
Let's ignore (for now) the whole wishy-washy is it an int or an object thing going on with "ed" and "_mdi". That leaves us to analyse.
void uvm_class_wizard() {
_control cInsertHeader;
frm = show("frm_uvm_class_wizard");
frm.cInsertHeader.p_value = _mdi.p_child.find('\S','LIHP@') ? 1 : 0;
}
It would probably help if I show you my first attempt at this code:
void uvm_class_wizard() {
frm = show("frm_uvm_class_wizard");
frm.cInsertHeader.p_value = _mdi.p_child.find('\S','LIHP@') ? 1 : 0;
}
That doesn't work. You get a "Control 'cInsertHeader' must be declared or cannot be a member of a non-struct/union/class type". Ok. Fair enough. It doesn't know what frm is. So I found the section about declaring controls. This seemed like the first logical attempt:
void uvm_class_wizard() {
_control cInsertHeader; // I assumed this affected the local variable cInsertHeader, not the nested variable cInsertHeader
frm = show("frm_uvm_class_wizard");
cInsertHeader = frm.cInsertHeader;
cInsertHeader.p_value = _mdi.p_child.find('\S','LIHP@') ? 1 : 0;
}
Nope. You get "left operand must be lvalue" on the assignment to cInsertHeader. Ok. I reread the example in the doc and try the following:
void uvm_class_wizard() {
_control cInsertHeader; // some how this reaches inside frm, and affects that variable
frm = show("frm_uvm_class_wizard");
frm.cInsertHeader.p_value = _mdi.p_child.find('\S','LIHP@') ? 1 : 0;
}
Yeah, it works! But this is mystical magical. I don't get what is going on here.
My best interpretation is, "_control cInsertHeader" is like a pragma that says, "next time you encounter 'cInsertHeader', treat whatever is in front of it as an id to a form.
Somebody went to a lot of trouble to make this language look superficially like C. This reminds me of what I've come to think of AppleScript, it's read only code. Already working code is quite readable, even if you don't know the language, but writing new code feels like searching for a magic incantation.
So if someone can explain to my simple C/Java style brain the proper way to interpret how that works, I'd greatly appreciate it. After that, may you can also explain how I can set and get the value of a "property" from a variable that is declared as an int.
Thanks,
Ryan