go to post Julius Kavay · Jan 20 ClassMethod Pyramide(n) { s a="#" f i=1:1:n w ?n-i,a,! s a=a_"##" } Maybe there is a shorter solution, I don't know...
go to post Julius Kavay · Jan 10 The bad news is,you have to be careful when you adapt delimited list to $list(). A stubborn change from a delimited list to $list() can become dangerous. The reason: set $piece(var,del,1) = value // piece 1 of var is ALWAYS a string set $list(var,1) = value // listitem 1 is either a number or a string kill x set $piece(x,",",1) = 100+1 write $zhex($p(x,",")) --> 257 kill x set $list(x,1) = 100+1 write $zhex($li(x,1)) --> 65 kill x set $piece(x,",",1) = 100 write $zhex($p(x,",")) --> 256 kill x set $list(x,1) = 100 write $zhex($li(x,1)) --> 64 kill x set $piece(x,",",1) = "100" write $zhex($p(x,",")) --> 256 kill x set $list(x,1) = "100" write $zhex($li(x,1)) --> 256 In other words, $list() retains the type of the expression whereas $piece() always converts it to a string. The good news is,there are just a few situations, where this could cause a problem, to tell the truth, in a nutshell, I can only think of two possibilities: $zhex() and $zboolean(). But who knows, what a mad programmer accomplish...
go to post Julius Kavay · Dec 22, 2022 If you want to reorder JSON properties (alphabetically or just put some of them at the beginning) then use a utility method, like this, especially if you have several object(types) to reorder Class DC.Utility Extends %RegisteredObject { /// Reorder a JSON Object or Array /// /// obj: JSON-Object /// ord: prop1, prop2, ... Desired order for (some) properties /// (Properties not listed are copied in the order in which they were created) /// If ord not present, properties will be reordered in aplphabetical order /// /// obj: JSON-Array /// ord: pos1, pos2, ... Desired order for (some) array items /// (Items not listed are copied in ascending order) /// ClassMethod ReOrder(obj As %DynamicAbstractObject, ord... As %String) { i obj.%Extends("%DynamicObject") { s new={}, itr=obj.%GetIterator() i '$g(ord) { while itr.%GetNext(.k) { s done(k)=0 } s k="" f s k=$o(done(k)) q:k="" d new.%Set(k,obj.%Get(k)) } else { f i=1:1:$g(ord) { s k=ord(i),done(k)=1 d:$e(obj.%GetTypeOf(k),1,2)'="un" new.%Set(k,obj.%Get(k)) } while itr.%GetNext(.k,.v) { d:'$d(done(k)) new.%Set(k,v) } } } elseif obj.%Extends("%DynamicArray") { s new=[], itr=obj.%GetIterator(), max=obj.%Size(), done="" f i=1:1:$g(ord) { s k=ord(i) i k,k<=max d new.%Push(obj.%Get(k-1)) s $bit(done,k)=1 } while itr.%GetNext(.k,.v) { d:'$bit(done,k+1) new.%Push(v) } } else { s new=obj } q new } } Some examples s car={"color":"red", "fuel":"diesel", "maxspeed":150, "maker":"Audi", "model":"Quattro Q5", "power":300, "available":true, "rating":8, "allWheel":true } s car1=##class(DC.Utility).ReOrder(car) // order all props alphabetically s car2=##class(DC.Utility).ReOrder(car,"maker","model","available") // start with maker, model, etc. w car.%ToJSON(),!,car1.%ToJSON(),!,car2.%ToJSON() ---> {"color":"red","fuel":"diesel","maxspeed":150,"maker":"Audi","model":"Quattro Q5","power":300,"available":true,"rating":8,"allWheel":true} {"allWheel":"1","available":"1","color":"red","fuel":"diesel","maker":"Audi","maxspeed":150,"model":"Quattro Q5","power":300,"rating":8} {"maker":"Audi","model":"Quattro Q5","available":"1","color":"red","fuel":"diesel","maxspeed":150,"power":300,"rating":8,"allWheel":"1"}
go to post Julius Kavay · Dec 16, 2022 Is NOT the same. You can it prove by adding a label to the line with the read command and a new line at the end // DOT VERSION // Use fic old Read *R:20 Else Do Quit ;;;; comando else aplicado a read. . Use 0 Write !!!,"Expired time." If $c(R)="a" d . Use 0 Write !!!,"A letter a has been read." . Quit write !,"If there are more lines, they will be executed",! quit // LITTLE BIT MODERN VERSION // Use fic new Read *R:20 If $Test { Use 0 Write !!!,"One character read" Quit } Else { Use 0 Write !!!,"Expired time." } write !,"If there are more lines, they will be executed",! quit now let run both of them... do old // let the timeout occur do old // now with some input do new // let the timeout occur do new // now with some input Do you see the difference? If there are more lines (at end) they will be executed in opposite cases (timeout/notimeout)
go to post Julius Kavay · Dec 15, 2022 Things are not so easy as they seem, you have to consider scopes too. Take the above class (DC.LineNumber) and add three more methods: ClassMethod CaseA(x) { if x goto zTest quit "A0" zTest quit "A1" } ClassMethod CaseB(x) { if x goto Test quit "B0" Test quit "B1" } ClassMethod Test() { write ..CaseA(0),..CaseA(1) set linenumber=..SrcLineNumberFromStack(.routine,.label,.offset,.src) do prt write ..CaseB(1),..CaseB(0) set linenumber=..SrcLineNumberFromStack(.routine,.label,.offset,.src) do prt quit // debug prt write !,"routine: ",routine write !,"label: ",label write !,"offset: ",offset write !,"linenumber: ",linenumber write !,"src:",src,!! } and now do the test: do ##class(DC.LineNumber).Test() and check the output... OK, I know, this is a (very) constructed case and shouldn't coincide with an everyday development style, but who knows, what a mad programer sometimes produces...
go to post Julius Kavay · Dec 13, 2022 It seems, there is a problem or (at least) a change: the above works (tested right now) in Cache-2018.1.1, IRIS 2019.1 and IRIS-2021.2 If it doesn't work in 2022.1 then the question is, why?
go to post Julius Kavay · Dec 13, 2022 It seems, we have to wait for someone with the same version installed as you, or you ask WRC. By the way, does the release notes for 2022.1 mentioned changes in dynamic classes?
go to post Julius Kavay · Dec 13, 2022 If you have just a few breaks, one of the possible solutions has been given by Robert Cemper. In case, you have tons of those breaks, you could execute the unit test in background: job ^performUnitTest assumed, your unittest can work in background and all the output goes, for example, in a file. The solution for the case you let run the unittest in a terminal session, could be something like this do turnOffBreaks, performUnitTest, turnOnBreaks The only problem is, to turn breaks off (or on), you need one view command, one $view() function and one $zutil() function (to get the right address for the view-s). Unfortunatelly, the use of the above tools is discouraged, so your best bet is, to ask WRC for a help.
go to post Julius Kavay · Dec 13, 2022 Are you sure, ..ObjOrigem contains a VALID object reference? Your output shows just a string "%Library.DynamicObject". A valid OREF looks like "nn@%Library.DynamicObject". What is the output of $isobject(..ObjOrigem)? Anyway, the $method(oref, "Propname"_"Get") works in IRIS, at least, in my IRIS 2021.2 USER>set obj={"Id":"myId"} USER>write $property(obj,"Id") --> myId USER>write $method(obj,"IdGet") --> myId USER>write $zv --> IRIS for UNIX (Ubuntu Server LTS for x86-64) 2021.2 (Build 649U) Thu Jan 20 2022 08:49:51 EST USER>write obj --> 5@%Library.DynamicObject