Reputation: 55
I am writing a script that should eventually be run from a drop down menu.
The parts of this script are:
The following is what I currently have. I have no declaration issues except that I am being told that I am trying to pass in null buffers in locations 1, 2 and 3 in the diff() function
//===Relevant declarations===
Object thiso, thato
Module thismod, thatmod // these have been assigned using my search function
Buffer diffResult = create
Buffer thisotext = create
Buffer thatotext = create
//===The problem child===
for thiso in thismod do {
for that o in thatmod do {
if(thiso."Reqid" "" == thato."Reqid" "") {
thisotext = thiso."Object Text"
thatotext = thato."Object Text"
diff(diffResult, thatotext, thisotext, "\\cf1\\strike","\\cf3\\u1") // here lies issue number 1
displayRichWithColor(stringOf(diffResult)) // commented out atm
delete thatotext
delete thisotext
delete diffResult
}
}
}
Things that I have checked:
I began learning DXL three weeks ago, so I am still a little new. This has me stumped, but I will continue trying different things as I wait to see if anyone has advice.
Thank you in advance to anyone who has the time to help.
Upvotes: 0
Views: 404
Reputation: 426
Okay! Took me a second, but I think I figured out why your first section of code failed.
//===Relevant declarations===
Object thiso, thato
Module thismod, thatmod // these have been assigned using my search function
Buffer diffResult = create
Buffer thisotext = create
Buffer thatotext = create
//===The problem child===
for thiso in thismod do {
for that o in thatmod do {
if(thiso."Reqid" "" == thato."Reqid" "") {
thisotext = thiso."Object Text"
thatotext = thato."Object Text"
diff(diffResult, thatotext, thisotext, "\\cf1\\strike","\\cf3\\u1") // here lies issue number 1
displayRichWithColor(stringOf(diffResult)) // commented out atm
delete thatotext
delete thisotext
delete diffResult
}
}
}
The issue here is in those 'delete' calls. The first time this is run, the very first object that matches all criteria ( thiso."Reqid" "" == thato."Reqid" "" ) will cause the buffers to be deleted and nulled out. The next successful match will just throw an error.
//===Relevant declarations===
Object thiso, thato
Module thismod, thatmod // these have been assigned using my search function
Buffer diffResult = create
Buffer thisotext = create
Buffer thatotext = create
//===The problem child===
for thiso in thismod do {
for thato in thatmod do {
if(thiso."Reqid" "" == thato."Reqid" "") {
thisotext = thiso."Object Text"
thatotext = thato."Object Text"
diff(diffResult, thatotext, thisotext, "\\cf1\\strike","\\cf3\\u1") // here lies issue number 1
displayRichWithColor(stringOf(diffResult)) // commented out atm
thatotext = ""
thisotext = ""
diffResult = ""
}
}
}
delete thatotext
delete thisotext
delete diffResult
This will clear the buffers in between comparisons but not destroy them. I think this behavior is also causing the issue in your functionalized example - you are repeatedly creating and destroying buffers rather than re-using the same buffer space.
Let me know how this goes!
Edit: Looking over your question, if you are embedding this in layout dxl, you may want to use the ( obj."Reqid" "" ) rather than the 'thiso in thismod' loop. Layout dxl is evaluated for each object, and 'obj' is effectively assigned as the handle to the object that the layout dxl is invoked from. Right now every object in is looping through every object.
Edit 2: Sample code
//===Relevant declarations===
Object thato
Module thatmod // these have been assigned using my search function
Buffer diffResult = create
Buffer thisotext = create
Buffer thatotext = create
//===The problem child===
for thato in thatmod do {
if(thiso."Reqid" "" == thato."Reqid" "") {
thisotext = obj."Object Text"
thatotext = thato."Object Text"
diff(diffResult, thatotext, thisotext, "\\cf1\\strike","\\cf3\\u1") // here lies issue number 1
displayRichWithColor(stringOf(diffResult)) // commented out atm
thatotext = ""
thisotext = ""
diffResult = ""
}
}
delete thatotext
delete thisotext
delete diffResult
Upvotes: 1
Reputation: 55
Okay, so I found a solution, although why it is a solution: I cannot say.
Essentially, I put the process into a function that I called for each object in thismod.
void CompareMod(Object o, Module thismod, Module thatmod) {
Object thato
Buffer diffResult = create
Buffer thisotext = create
Buffer thatotext = create
for thato in thatmod do {
if(o."Reqid" "" == thato."Reqid" "") {
thisotext = o."Object Text"
thatotext = thato."Object Text"
diff(diffResult, thatotext, thisotext, "\\cf1\\strike", "\\cf3\\u1")
displayRichWithColor(stringOf(diffResult))
delete thatotext
delete thisotext
delete diffResult
}
}
}
for thiso in thismod do {
CompareMod(thiso, thismod, thatmod)
}
On top of this, I have a new issue that I will now pursue. Instead of posting what I would expect, showing the differences between similar boxes of text, I instead just get a printout of the the sections that are the same of ALL of the objects in thatmod repeated for each object in thismod.
So this is my new project to solve, I will accept help on this as well, or I shall post a new question in the future.
Upvotes: 0