// This demonstrates reusing global variables through multiple executions. // when those are within a few seconds of eachother. // // Copy this script to the Script Addins folder, or drag and drop it on // the scripts page. When installed, rightclick the column header in a // tab and select Columns->Script->TestColumn. // Notice has a different number for each entry. If you refresh (F5) // repeatedly, notice how the numbers increase each time. // // If you open the script log, then you can also see that the same // is true for the vector attached to vgTestRegexes. In other words // it displays "Reading from config" once, and the rest has // displays "Use previously loaded" // ------------------------------------------------- var vgTestRegexes; var giCounter; function OnInit(initData){ initData.name = "Test"; initData.desc = "Test"; initData.copyright = "myarmor"; initData.min_version="11.8"; initData.version = "0.1"; initData.default_enable = true; initData.config.TestRegexes=DOpus.Create.Vector(); } function OnAddColumns(addColData){ var col; col = addColData.AddColumn(); col.name = "TestCol"; col.method = "OnTestCol"; col.label = "TestColumn"; col.autogroup = false; col.namerefresh=true; col.justify = "left"; col.type = "number"; } function OnScriptConfigChange(configChangeData){ Script.RefreshColumn('TestCol'); } // Handler for the TestCol column function OnTestCol(scriptColData){ if (scriptColData.col!="TestCol"){ return; } // Check if we have a used variable. if (typeof vgTestRegexes==='undefined'){ // if not, initialize it. DOpus.Output('Reading from config'); vgTestRegexes=Script.config.TestRegexes; } else { // if we do, use the previous one. DOpus.Output('Use previously loaded'); } // Check if we have a used variable. if (typeof giCounter==='undefined'){ // if not, initialize it. giCounter=0; } giCounter++; scriptColData.value = giCounter; }