Hello I am getting an Access Violation at the exact point in my code I try to delete a buffer. I am attempting to use buffers to populate an array to populate a dxl attribute for display in a column based on 7 different logic cases. I was previously using different dxl attribute columns to return TRUE based on a Gap case, and now I'm attempting to roll them into one column with descriptive text of the gap rather than just TRUE. So, I'm getting the Access Violation error at line 233 the first time I try to delete a buffer. I am out of ideas, please have a look and gimme some suggestions. Thanks
/*
Rich Mason 05252018
The code below is intended to find several different gap cases and display relevant text describing it in one column
See Attribute Value Check.txt for all generic code cases
*/
//DXL ATTR TO USE FOR THIS FUNCTION : Gaps All
///////////Begin Constants and Strings defined
LinkRef lr = null
bool hasinlink = false
Link l = null
bool hasoutlink = false
string stringToAnalyze1=obj."Object Text"
string stringToAnalyze2=obj."Type"
string stringToAnalyze3=obj."Rationale"
string stringToAnalyze4=obj."Allocation"
string stringToAnalyze5=obj."Assignment"
string stringToAnalyze6=obj."Category"
string stringToAnalyze7=obj."ITS_Object_Type"
string stringToAnalyze8=obj."Status"
string stringToAnalyze9=obj."Object Heading"
string stringToAnalyze10=obj."TableType"
Module mod = current Module
ModuleVersion mv = null ModuleVersion
ModuleProperties mp = null ModuleProperties
mv = moduleVersion(mod)
getProperties(mv, mp)
string doctype = mp."ITS_Document_Type"
Array Gaps = create (100,10)
string GapsbuffAll
string Gapsbuff1
string Gapsbuff2
string Gapsbuff3
string Gapsbuff4
string Gapsbuff5
string Gapsbuff6
string Gapsbuff7
///////////End of Constants and Strings defined
//////*******Problem now becomes how to create a buffer to display everything********/////////
//*****////Begin Case 1 Loop
///////////derived requirements that do not have a rationale
//IF Object Text contains Shall
if(matches("shall", stringToAnalyze1)){
//AND Type is Derived
if(matches("Derived", stringToAnalyze2)){
//AND Rationale is empty
if(stringToAnalyze3 == null){
//begin new buffer Gapsbuff1
Buffer b1 = create()
b1 = "Derived and no Rationale"
putString (Gaps, stringOf(b1),1,1)
}
//end buffer Gapsbuff1
} //end of Type loop
} //end of Object Text loop
//delete (b1)
//******////End Case 1 Loop
//******////Begin Case 2 Loop
///////////allocated OR assigned requirements that do not have an Inlink
//IF Object Text contains Shall
if(matches("shall", stringToAnalyze1)){
//AND Allocation OR Assignment are not empty
if(stringToAnalyze4 != null || stringToAnalyze5 != null){
//AND no Inlink
for lr in obj <- "*" do {
hasinlink = true
break }
if (hasinlink != true) {
//begin new buffer Gapsbuff2
Buffer b2 = create()
b2 = "Allocated or Assigned & No Inlink"
putString (Gaps, stringOf(b2), 1,2)
//end buffer Gapsbuff2
}
}
}
//delete (b2)
//******////End Case 2 Loop
//******////Begin Case 3 Loop
///////////requirements with inlinks that do not have an Allocation or Assignment
//IF Object Text contains Shall
if(matches("shall", stringToAnalyze1)){
//AND Allocation OR Assignment is empty (if both are empty)
if(stringToAnalyze4 == null && stringToAnalyze5 == null){
//AND Inlink
for lr in obj <- "*" do {
hasinlink = true
break }
if (hasinlink == true) {
//begin new buffer Gapsbuff3
Buffer b3 = create()
b3 = "Has Inlinks but no Allocation or Assignment"
putString (Gaps, stringOf(b3), 1,3)
//end buffer Gapsbuff3
}
}
}
//delete (b3)
//******////End Case 3 Loop
//******////Begin Case 4 Loop
///////////requirements that do not have an Category = Technical or ITS Object Type = Requirement
//IF Object Text contains Shall
if(matches("shall", stringToAnalyze1)){
//AND Category !=Technical OR ITS Object Type != Requirement
if ((stringToAnalyze6 != "Technical" && stringToAnalyze2 != "Functional") || stringToAnalyze7 != "Requirement"){
//begin new buffer Gapsbuff4
Buffer b4 = create()
b4 = "Requirement with Category not Technical or Object Type not Requirement"
putString (Gaps, stringOf(b4), 1,4)
//end buffer Gapsbuff4
}
} //end of Object Text loop
//delete (b4)
//******////End Case 4 Loop
//******////Begin Case 5 Loop
///////////objects that do not have an Status, Category, Type or ITS Object Type populated with consideration for Object Headings
//[(Status empty || Type empty) && Object Heading empty && Category != Information && Not a table cell]
if ((((stringToAnalyze8 == null || stringToAnalyze2 == null) && stringToAnalyze9 == null && stringToAnalyze6 != "Information") && stringToAnalyze10 =="TableNone") || (stringToAnalyze6 == null && stringToAnalyze10 =="TableNone") || (stringToAnalyze7 == null && stringToAnalyze10 =="TableNone")){
/*
//OR Category empty && Not a table cell
else if (stringToAnalyze6 == null && stringToAnalyze10 =="TableNone") {
//OR ITS Object Type empty && Not a table cell
else if (stringToAnalyze7 == null && stringToAnalyze10 =="TableNone") {
*/
//begin new buffer Gapsbuff5
Buffer b5 = create()
b5 = "Category, Status, Type, or ITS Object Type empty"
putString (Gaps, stringOf(b5), 1,5)
//end buffer Gapsbuff5
// }
// }
}
//delete (b5)
//******////End Case 5 Loop
//******////Begin Case 6 Loop
///////////requirements that do not have Outlink that are not derived
//IF Object Text contains Shall
if(matches("shall", stringToAnalyze1)){
//AND Type is not Derived
if(stringToAnalyze2 != "Derived"){
//AND ITS_Document_Type is not Customer
if(!matches("Customer", doctype)){
//AND no Outlink
for l in obj -> "*" do {
hasoutlink = true
break }
if (hasoutlink != true) {
//begin new buffer Gapsbuff6
Buffer b6 = create()
b6 = "Requirement not Derived with no Outlink"
putString (Gaps, stringOf(b6), 1,6)
//end buffer Gapsbuff6
}
}
}
}
//delete (b6)
//******////End Case 6 Loop
//******////Begin Case 7 Loop
///////////objects with outlinks that are not traceable requirements
//IF Object Text does not contain Shall or Category not Technical or ITS Object Type not Requirement or Type not Basic
if(!matches("shall", stringToAnalyze1) || stringToAnalyze6 != "Technical" || stringToAnalyze7 != "Requirement" || stringToAnalyze2 != "Basic"){
//AND has Outlink
for l in obj -> "*" do {
hasoutlink = true
break }
if (hasoutlink == true) {
//begin new buffer Gapsbuff7
Buffer b7 = create()
b7 = "Not a Requirement, Should not have Outlink"
putString (Gaps, stringOf(b7), 1,7)
//end buffer Gapsbuff7
}
//delete (b7)
//Gaps string that pulls it all together, put after last case logic
Gapsbuff1 = (string get (Gaps,1,1,99))
Gapsbuff2 = (string get (Gaps,1,2,99))
Gapsbuff3 = (string get (Gaps,1,3,99))
Gapsbuff4 = (string get (Gaps,1,4,99))
Gapsbuff5 = (string get (Gaps,1,5,99))
Gapsbuff6 = (string get (Gaps,1,6,99))
Gapsbuff7 = (string get (Gaps,1,7,99))
GapsbuffAll = Gapsbuff1 " \n" Gapsbuff2 " \n" Gapsbuff3 " \n" Gapsbuff4 " \n" Gapsbuff5 " \n" Gapsbuff6 " \n" Gapsbuff7
obj.attrDXLName = GapsbuffAll
}
//}
//******////End Case 7 Loop
//*****delete all buffs
delete(b1)
delete(b2)
delete(b3)
delete(b4)
delete(b5)
delete(b6)
delete(b7)
//*****delete array
delete(Gaps)
Rich M - Wed May 30 08:58:49 EDT 2018 |
Re: Error when delete buffer Two things: 1. You are declaring and creating your buffers inside if/loops-statements. Once you "exist" the loop/if-block you cannot access this variable anymore from outside. Your delete calls are at the end of the code, where none of these variables are usable anymore. To fix this you can declare(and depending on usecase even create) the Buffer variables at the top, then your code wont crash. Alternatively call delete inside the block where you declare/create the buffer and delete them as soon as you don't need them anymore. 2. For what you are doing in this script you don't need buffers at all. Instead of doing: Buffer b7 = create() b7 = "Not a Requirement, Should not have Outlink" putString (Gaps, stringOf(b7), 1,7) you can just do: string s = "Not a Requirement, Should not have Outlink" putString (Gaps, s, 1,7) and forget about the whole deleting business. Buffers have a good use, mainly if you do an insane amount of string concatenating... but for small cases like this you can just use strings directly.
P.S.: Your code above only works because you are using the "autodeclare variables" feature in DOORS. Without that feature DOORS would have told you that b1-b7 are undeclared in lines 230+. With the feature it is just declaring these variables itself and trying to delete them right after. I guess that's also where it then ends up throwing the access violation.
|
Re: Error when delete buffer Thanks for the feedback. Got it to work by getting rid of the buffers. Final code looks like
/*
Rich Mason 05252018
The code below is intended to find several different gap cases and display relevant text describing it in one column
See Attribute Value Check.txt for all generic code cases
*/
//DXL ATTR TO USE FOR THIS FUNCTION : Gaps All
///////////Begin Constants and Strings defined
string stringToAnalyze1=obj."Object Text"
string stringToAnalyze2=obj."Type"
string stringToAnalyze3=obj."Rationale"
string stringToAnalyze4=obj."Allocation"
string stringToAnalyze5=obj."Assignment"
string stringToAnalyze6=obj."Category"
string stringToAnalyze7=obj."ITS_Object_Type"
string stringToAnalyze8=obj."Status"
string stringToAnalyze9=obj."Object Heading"
string stringToAnalyze10=obj."TableType"
Module mod = current Module
ModuleVersion mv = null ModuleVersion
ModuleProperties mp = null ModuleProperties
mv = moduleVersion(mod)
getProperties(mv, mp)
string doctype = mp."ITS_Document_Type"
Array Gaps = create (100,10)
string GapsbuffAll
string Gapsbuff1
string Gapsbuff2
string Gapsbuff3
string Gapsbuff4
string Gapsbuff5
string Gapsbuff6
string Gapsbuff7
///////////End of Constants and Strings defined
//*****////Begin Case 1 Loop
///////////derived requirements that do not have a rationale
//IF Object Text contains Shall
if(matches("shall", stringToAnalyze1)){
//AND Type is Derived
if(matches("Derived", stringToAnalyze2)){
//AND Rationale is empty
if(stringToAnalyze3 == null){
string b1 = "**Derived and no Rationale**"
putString (Gaps, b1,1,1)
}
} //end of Type loop
} //end of Object Text loop
//******////End Case 1 Loop
//******////Begin Case 2 Loop
///////////allocated OR assigned requirements that do not have an Inlink
//IF Object Text contains Shall
if(matches("shall", stringToAnalyze1)){
//AND Allocation OR Assignment are not empty
if(stringToAnalyze4 != null || stringToAnalyze5 != null){
//AND no Inlink
LinkRef lr
bool hasinlink = false
for lr in obj <- "*" do {
hasinlink = true
break
}
if (hasinlink != true) {
string b2 = "**Allocated or Assigned & No Inlink**"
putString (Gaps, b2, 1,2)
}
}
}
//******////End Case 2 Loop
//******////Begin Case 3 Loop
///////////requirements with inlinks that do not have an Allocation or Assignment
//IF Object Text contains Shall
if(matches("shall", stringToAnalyze1)){
//AND Allocation OR Assignment is empty (if both are empty)
if(stringToAnalyze4 == null && stringToAnalyze5 == null){
//AND Inlink
LinkRef lr
bool hasinlink = false
for lr in obj <- "*" do {
hasinlink = true
break
}
if (hasinlink == true) {
string b3 = "**Has Inlinks but no Allocation or Assignment**"
putString (Gaps, b3, 1,3)
}
}
}
//******////End Case 3 Loop
//******////Begin Case 4 Loop
///////////requirements that do not have an Category = Technical or ITS Object Type = Requirement
//IF Object Text contains Shall
if(matches("shall", stringToAnalyze1)){
//AND Category !=Technical OR ITS Object Type != Requirement
if ((stringToAnalyze6 != "Technical" && stringToAnalyze2 != "Functional") || stringToAnalyze7 != "Requirement"){
string b4 = "**Requirement with Category not Technical or Object Type not Requirement**"
putString (Gaps, b4, 1,4)
}
}
//******////End Case 4 Loop
//******////Begin Case 5 Loop
///////////objects that do not have an Status, Category, Type or ITS Object Type populated with consideration for Object Headings
//[(Status empty || Type empty) && Object Heading empty && Category != Information && Not a table cell]
if ((((stringToAnalyze8 == null || stringToAnalyze2 == null) && stringToAnalyze9 == null && stringToAnalyze6 != "Information") && stringToAnalyze10 =="TableNone") || (stringToAnalyze6 == null && stringToAnalyze10 =="TableNone") || (stringToAnalyze7 == null && stringToAnalyze10 =="TableNone")){
string b5 = "**Category, Status, Type, or ITS Object Type empty**"
putString (Gaps, b5, 1,5)
}
//******////End Case 5 Loop
//******////Begin Case 6 Loop
///////////requirements that do not have Outlink that are not derived
//IF Object Text contains Shall
if(matches("shall", stringToAnalyze1)){
//AND Type is not Derived
if(stringToAnalyze2 != "Derived"){
//AND ITS_Document_Type is not Customer
if(!matches("Customer", doctype)){
//AND no Outlink
Link l
bool hasoutlink = false
for l in obj -> "*" do {
hasoutlink = true
break
}
if (hasoutlink != true) {
string b6 = "**Requirement not Derived with no Outlink**"
putString (Gaps, b6, 1,6)
}
}
}
}
//******////End Case 6 Loop
//******////Begin Case 7 Loop
///////////objects with outlinks that are not traceable requirements
//IF Object Text does not contain Shall or Category not Technical or ITS Object Type not Requirement or Type not Basic
if(!matches("shall", stringToAnalyze1) || stringToAnalyze6 != "Technical" || stringToAnalyze7 != "Requirement" || stringToAnalyze2 != "Basic"){
//AND has Outlink
Link l
bool hasoutlink = false
for l in obj -> "*" do {
hasoutlink = true
break
}
if (hasoutlink == true) {
string b7 = "**Not a Requirement, Should not have Outlink**"
putString (Gaps, b7, 1,7)
}
}
//******////End Case 7 Loop
//Gaps string that pulls it all together, put after last case logic
Gapsbuff1 = (string get (Gaps,1,1,99))
Gapsbuff2 = (string get (Gaps,1,2,99))
Gapsbuff3 = (string get (Gaps,1,3,99))
Gapsbuff4 = (string get (Gaps,1,4,99))
Gapsbuff5 = (string get (Gaps,1,5,99))
Gapsbuff6 = (string get (Gaps,1,6,99))
Gapsbuff7 = (string get (Gaps,1,7,99))
/*
//want GapsbuffAll to check if a buffer is not empty and only if not empty then concatenate the buff for display
while (!null Gapsbuff1 || Gapsbuff2 || Gapsbuff3 || Gapsbuff4 || Gapsbuff5 || Gapsbuff6 || Gapsbuff7) {
GapsbuffAll = Gapsbuff1 " \n" Gapsbuff2 " \n" Gapsbuff3 " \n" Gapsbuff4 " \n" Gapsbuff5 " \n" Gapsbuff6 " \n" Gapsbuff7
*/
GapsbuffAll = Gapsbuff1 " \n" Gapsbuff2 " \n" Gapsbuff3 " \n" Gapsbuff4 " \n" Gapsbuff5 " \n" Gapsbuff6 " \n" Gapsbuff7
obj.attrDXLName = GapsbuffAll
//*****delete array
delete(Gaps)
alternatively, I was able to get it work with buffers as well by using your suggestion. module performance seems to be about the same either way.
/*
Rich Mason 05252018
The code below is intended to find several different gap cases and display relevant text describing it in one column
See Attribute Value Check.txt for all generic code cases
*/
//DXL ATTR TO USE FOR THIS FUNCTION : Gaps All
///////////Begin Constants and Strings defined
string stringToAnalyze1=obj."Object Text"
string stringToAnalyze2=obj."Type"
string stringToAnalyze3=obj."Rationale"
string stringToAnalyze4=obj."Allocation"
string stringToAnalyze5=obj."Assignment"
string stringToAnalyze6=obj."Category"
string stringToAnalyze7=obj."ITS_Object_Type"
string stringToAnalyze8=obj."Status"
string stringToAnalyze9=obj."Object Heading"
string stringToAnalyze10=obj."TableType"
Module mod = current Module
ModuleVersion mv = null ModuleVersion
ModuleProperties mp = null ModuleProperties
mv = moduleVersion(mod)
getProperties(mv, mp)
string doctype = mp."ITS_Document_Type"
Array Gaps = create (100,10)
string GapsbuffAll
string Gapsbuff1
string Gapsbuff2
string Gapsbuff3
string Gapsbuff4
string Gapsbuff5
string Gapsbuff6
string Gapsbuff7
//Create all the buffers
Buffer b1 = create()
Buffer b2 = create()
Buffer b3 = create()
Buffer b4 = create()
Buffer b5 = create()
Buffer b6 = create()
Buffer b7 = create()
///////////End of Constants and Strings defined
//*****////Begin Case 1 Loop
///////////derived requirements that do not have a rationale
//IF Object Text contains Shall
if(matches("shall", stringToAnalyze1)){
//AND Type is Derived
if(matches("Derived", stringToAnalyze2)){
//AND Rationale is empty
if(stringToAnalyze3 == null){
//begin new buffer Gapsbuff1
b1 = "**Derived and no Rationale**"
putString (Gaps, stringOf(b1),1,1)
}
} //end of Type loop
} //end of Object Text loop
//******////End Case 1 Loop
//******////Begin Case 2 Loop
///////////allocated OR assigned requirements that do not have an Inlink
//IF Object Text contains Shall
if(matches("shall", stringToAnalyze1)){
//AND Allocation OR Assignment are not empty
if(stringToAnalyze4 != null || stringToAnalyze5 != null){
//AND no Inlink
LinkRef lr = null
bool hasinlink = false
for lr in obj <- "*" do {
hasinlink = true
break }
if (hasinlink != true) {
//begin new buffer Gapsbuff2
b2 = "**Allocated or Assigned & No Inlink**"
putString (Gaps, stringOf(b2), 1,2)
//end buffer Gapsbuff2
}
}
}
//******////End Case 2 Loop
//******////Begin Case 3 Loop
///////////requirements with inlinks that do not have an Allocation or Assignment
//IF Object Text contains Shall
if(matches("shall", stringToAnalyze1)){
//AND Allocation OR Assignment is empty (if both are empty)
if(stringToAnalyze4 == null && stringToAnalyze5 == null){
//AND Inlink
LinkRef lr = null
bool hasinlink = false
for lr in obj <- "*" do {
hasinlink = true
break }
if (hasinlink == true) {
//begin new buffer Gapsbuff3
b3 = "**Has Inlinks but no Allocation or Assignment**"
putString (Gaps, stringOf(b3), 1,3)
//end buffer Gapsbuff3
}
}
}
//******////End Case 3 Loop
//******////Begin Case 4 Loop
///////////requirements that do not have an Category = Technical or ITS Object Type = Requirement
//IF Object Text contains Shall
if(matches("shall", stringToAnalyze1)){
//AND Category !=Technical OR ITS Object Type != Requirement
if ((stringToAnalyze6 != "Technical" && stringToAnalyze2 != "Functional") || stringToAnalyze7 != "Requirement"){
//begin new buffer Gapsbuff4
b4 = "**Requirement with Category not Technical or Object Type not Requirement**"
putString (Gaps, stringOf(b4), 1,4)
}
} //end of Object Text loop
//******////End Case 4 Loop
//******////Begin Case 5 Loop
///////////objects that do not have an Status, Category, Type or ITS Object Type populated with consideration for Object Headings
//[(Status empty || Type empty) && Object Heading empty && Category != Information && Not a table cell]
if ((((stringToAnalyze8 == null || stringToAnalyze2 == null) && stringToAnalyze9 == null && stringToAnalyze6 != "Information") && stringToAnalyze10 =="TableNone") || (stringToAnalyze6 == null && stringToAnalyze10 =="TableNone") || (stringToAnalyze7 == null && stringToAnalyze10 =="TableNone")){
//begin new buffer Gapsbuff5
b5 = "**Category, Status, Type, or ITS Object Type empty**"
putString (Gaps, stringOf(b5), 1,5)
//end buffer Gapsbuff5
}
//******////End Case 5 Loop
//******////Begin Case 6 Loop
///////////requirements that do not have Outlink that are not derived
//IF Object Text contains Shall
//Buffer b6 = create()
if(matches("shall", stringToAnalyze1)){
//AND Type is not Derived
if(stringToAnalyze2 != "Derived"){
//AND ITS_Document_Type is not Customer
if(!matches("Customer", doctype)){
//AND no Outlink
Link l = null
bool hasoutlink = false
for l in obj -> "*" do {
hasoutlink = true
break }
if (hasoutlink != true) {
b6 = "**Requirement not Derived with no Outlink**"
putString (Gaps, stringOf(b6), 1,6)
}
}
}
}
//******////End Case 6 Loop
//******////Begin Case 7 Loop
///////////objects with outlinks that are not traceable requirements
//IF Object Text does not contain Shall or Category not Technical or ITS Object Type not Requirement or Type not Basic
if(!matches("shall", stringToAnalyze1) || stringToAnalyze6 != "Technical" || stringToAnalyze7 != "Requirement" || stringToAnalyze2 != "Basic"){
//AND has Outlink
Link l = null
bool hasoutlink = false
for l in obj -> "*" do {
hasoutlink = true
break }
if (hasoutlink == true) {
b7 = "**Not a Requirement, Should not have Outlink**"
putString (Gaps, stringOf(b7), 1,7)
}
}
//******////End Case 7 Loop
//Gaps string that pulls it all together, put after last case logic
Gapsbuff1 = (string get (Gaps,1,1,99))
Gapsbuff2 = (string get (Gaps,1,2,99))
Gapsbuff3 = (string get (Gaps,1,3,99))
Gapsbuff4 = (string get (Gaps,1,4,99))
Gapsbuff5 = (string get (Gaps,1,5,99))
Gapsbuff6 = (string get (Gaps,1,6,99))
Gapsbuff7 = (string get (Gaps,1,7,99))
/*
//want GapsbuffAll to check if a buffer is not empty and only if not empty then concatenate the buff for display
while (!null Gapsbuff1 || Gapsbuff2 || Gapsbuff3 || Gapsbuff4 || Gapsbuff5 || Gapsbuff6 || Gapsbuff7) {
GapsbuffAll = Gapsbuff1 " \n" Gapsbuff2 " \n" Gapsbuff3 " \n" Gapsbuff4 " \n" Gapsbuff5 " \n" Gapsbuff6 " \n" Gapsbuff7
*/
GapsbuffAll = Gapsbuff1 " \n" Gapsbuff2 " \n" Gapsbuff3 " \n" Gapsbuff4 " \n" Gapsbuff5 " \n" Gapsbuff6 " \n" Gapsbuff7
obj.attrDXLName = GapsbuffAll
//*****delete all buffs
delete(b1)
delete(b2)
delete(b3)
delete(b4)
delete(b5)
delete(b6)
delete(b7)
//*****delete array
delete(Gaps)
|
Re: Error when delete buffer quick follow up.....I seem to be having a ton of white space at the end of the code I put in the comment. Any idea how to get rid of it? I'm only pasting from the actual code in Notepad++ without any extra space. Thanks |
Re: Error when delete buffer Rich M - Wed May 30 13:46:54 EDT 2018 quick follow up.....I seem to be having a ton of white space at the end of the code I put in the comment. Any idea how to get rid of it? I'm only pasting from the actual code in Notepad++ without any extra space. Thanks That's a issue with this forum and nothing you can change easily. The more code is contained in a code-block, the worse the whitespace issue becomes. |