![]() |
Telelogic DOORS (steve huntington) | ![]() |
new topic :
profile :
search :
help :
dashboard :
calendar :
home
|
||
Latest News:
|
|
Topic Title: In-line a string array into a function call? Topic Summary: Created On: 22-Jan-2008 20:03 Status: Post and Reply |
Linear : Threading : Single : Branch |
![]() |
![]()
|
![]() |
|
Is it possible to put a string array directly in-line in a function call? This example will show what I mean:
// This works... string ans[] = {"Yes","No"} DB xDB = centered "Sample" DBE xRadio = radioBox(xDB,"Your answer?",ans,0) show xDB // This does not work... DB xDB = centered "Sample" DBE xRadio = radioBox(xDB,"Your answer?",{"Yes","No"},0) show xDB Is there any proper syntax to do this? |
|
![]() |
|
![]() |
|
I don't think it's possible, though I've been wrong before.
------------------------- Scott Boisvert Engineering Tools Administrator L-3 Communications - Avionics Systems scott.boisvert@l-3com.com |
|
![]() |
|
![]() |
|
Surely, good programming practice would prohibit having string literals used in this way even if it were possible.
------------------------- Tony Goodman http://www.smartdxl.com |
|
![]() |
|
![]() |
|
Yes, it's probably not good programming practice. However, I run into all kinds of problems (memory corruption and DOORS crashes) when I try to define local string arrays inside of functions. The following set of simple DXL programs will highlight the issue.
// This works fine DBE fnAddTab(DB xDB) { void fnDoNothing(DBE xTab) {} string options[] = {"One","Two"} DBE xTab = tab(xDB,options,400,200,fnDoNothing) return xTab } DB xDB = centered "Sample" DBE xTab = fnAddTab(xDB) show xDB // This demonstrates corrupted tab labels DBE fnAddTab(DB xDB) { void fnDoNothing(DBE xTab) {} string options[] = {"One","Two"} DBE xTab = tab(xDB,options,400,200,fnDoNothing) return xTab } DBE fnAddText(DB xDB) { string xLabel = "This is some sample text" string xInitial = "This is a bunch of meaningless text." DBE xText = text(xDB,xLabel,xInitial,400,200,false) return xText } DB xDB = centered "Sample" DBE xTab = fnAddTab(xDB) DBE xText = fnAddText(xDB) show xDB // This crashes DOORS DBE fnAddTab(DB xDB) { void fnDoNothing(DBE xTab) {} string options[] = {"One","Two","Three"} DBE xTab = tab(xDB,options,400,200,fnDoNothing) return xTab } DBE fnAddText(DB xDB) { string xLabel = "This is some sample text" string xInitial = "This is a bunch of meaningless text." DBE xText = text(xDB,xLabel,xInitial,400,200,false) return xText } DB xDB = centered "Sample" DBE xTab = fnAddTab(xDB) DBE xText = fnAddText(xDB) show xDB // This works again (define global string arrays) string options[] = {"One","Two","Three"} DBE fnAddTab(DB xDB) { void fnDoNothing(DBE xTab) {} DBE xTab = tab(xDB,options,400,200,fnDoNothing) return xTab } DBE fnAddText(DB xDB) { string xLabel = "This is some sample text" string xInitial = "This is a bunch of meaningless text." DBE xText = text(xDB,xLabel,xInitial,400,200,false) return xText } DB xDB = centered "Sample" DBE xTab = fnAddTab(xDB) DBE xText = fnAddText(xDB) show xDB So, I have a very large dialog box, with many DBEs that require string arrays (tab strips, choice, radio, check, etc.). I've tried to use good programming practice by breaking up my code into functions. However, you cannot define string arrays locally without quickly running into problems. This means you must define all string arrays globably, which is also not good programming practice. I submitted a DOORS trouble ticket a while ago about a similar issue and was told that DXL does not properly pass arrays back and forth between functions. Something about how once you pass the string array back from the function, that memory space is no longer protected and will get written over by other parts of your program. That's why, in the scripts above, the first one works, the second one is corrupted, and the third one completely crashed DOORS. I was hoping I might be able to get around this problem by defining these string arrays in-line in the function definitions. Oh well. |
|
![]() |
|
![]() |
|
Yes string arrays that are used for DBEs need to be global since it needs to be accessed outside of the function.
I declare them as "const" to maintain good programming practice. ------------------------- David Pechacek AAI Services Textron dpechacek@sc-aaicorp.com David.Pechacek@gmail.com |
|
![]() |
|
![]() |
|
To clarify, the TAB and other DBEs store the address of the array when defined, and go to that address is consulted when the Dialog is 'realized'. If the array is defined in the local function that defines the DBE, then that area of the stack is invalid at the time the dialog is Realized, and you experience your corruption problem. You will probably have the same problem if you were able to insert a constant array into the TAB command.
Thus, these array's regrettably need to be defined globally so they are not subject to whims of the Stack. - Louie |
|
![]() |
|
![]() |
|
Sorry Louie. I meant I define them as "const" but globally. So they can't be modified.
------------------------- David Pechacek AAI Services Textron dpechacek@sc-aaicorp.com David.Pechacek@gmail.com |
|
![]() |
|
![]() |
|
The keyword const is useful for documenting your code but does not actually create a constant. Values can be modified.
// prints out 2 and 3. const int i = 2 print i "\n" i = 3 print i "\n" I always use const and use a naming convention for "constants" which is all uppercase letters. This way I know to treat them as constants. ------------------------- Tony Goodman http://www.smartdxl.com Edited: 24-Jan-2008 at 14:39 by Tony Goodman |
|
![]() |
Telelogic DOORS
» DXL Exchange
»
In-line a string array into a function call?
|
![]() |
FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.