I opened another thread for this question:
void makeDialog(DB x) {
string myArr[] = {"123","345","567"}
checkBox (x, "Choices:", myArr,0)
realize x // Comment me out and this will not work ...
myArr[0] = addr_ 0 // trash the array for good
myArr[1] = addr_ 0
myArr[2] = addr_ 0
}
DB diag = create "Test"
makeDialog diag
show diag
int getSize (Skip k) {int i = 0; int v; for v in sk do i++; return i }
void fillArrayWithValues (string ar[], Skip sk) { ... fill array from Skip ... }
void makeMyDialog (DB diag, Skip myCheckBoxOption1, Skip MyCheckBoxOption2) {
DBE element = edit (...)
...
string sArCheck1[getSize myCheckBoxOption1];
fillArrayWithValues (sArCheck1, myCheckBoxOption1)
DBE checks1 = checkBox (diag, "MyLabel", sArCheck1, 0)
...
string sArCheck1[getSize myCheckBoxOption1];
fillArrayWithValues (sArCheck1, myCheckBoxOption2)
DBE checks1 = checkBox (diag, "MyLabel", sArCheck1, 0)
// realize the dialog, when it is built, so our checkboxes stay alright
realize diag
}
void makeEnumerationDialog (Module m, string enumName) {
Skip vals = getValuesForEnumeration(m, enumName)
DB myDialog = create "Choose a value:"
makeMyDialog myDialog
block myDialog
// .... do something ....
}
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
Mathias Mamsch - Tue Jun 01 11:50:10 EDT 2010 |
Re: Checkbox memory problem (was: returning an array) Summarizing: 1) checkBox(); // string[] storage certainly must be valid here 2) realize(); // string[] storage certainly must be valid here as well 3) show(); // string[] storage may be out of scope here without adverse side-effects After realize() is called I could keep track of the association between (1) DBE checkBox objects, (2) label values, and (3) whether they are checked or not with some other data structure and let the string[] storage go out of scope. Thanks for the advice and I'll post if there are any issues. Also, I did not see a delete()/destroy() function for DBE objects. Do these go down with the DB object? |