Checkbox memory problem (was: returning an array)

I opened another thread for this question:

@Fu Lin Yiu: I think what you say is not exactly right ... When I create a dialog with checkboxes, as soon as I realize or show the dialog box the checkboxes stay alright later.
 

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

 


This means a program that comes without putting string arrays to buffers, would could have code like this:

 

 

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 ....
}




I guess this is not too bad?! And it should be maintainable. I think arrays might just not be the right datatype to pass around in functions ... Mathias



 

 

 


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)
SystemAdmin - Tue Jun 01 17:27:22 EDT 2010

So after realize() the string array storage can perish? I think I can work with that. The only reason I was using stringhttp://] variables is checkBoxes needed them. I saw some other posts saying it was not good enough to let string['s die after the call to the checkBox() function. I assumed they had to keep existing as long as the dialog was displayed.

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?