Search code examples
ibm-doors

Null buffer calls for diff(buffres, buff1, buff2, rich text bits) in layoutDXL compare module script


I am writing a script that should eventually be run from a drop down menu.

The parts of this script are:

  1. A search that takes the name of the current module and combs the database for modules of the same name (working)
  2. A script that creates a column and calls the layout dxl described in (3.)(working-ish, but not my main problem)
  3. Layout DXL that compares the objects of the module.

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:

  • thiso."Object Text" and thato."Object Text" produce non-null strings. The DXL manual shows me that my assignment method is correct.

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.


Solution

  • 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