I find myself needing to check if two variables point to the same object. Here is a naive attempt that does not work (it should have said "True"):
BrightScript Debugger> A = { }
BrightScript Debugger> B = A
BrightScript Debugger> ? A = B
Type Mismatch. (runtime error &h18) in $LIVECOMPILE(1197)
Here is a practical situation: i want to display multiple elements on roScreen and that job is delegated to a Manager object. Manager's job is to keep list of the elements and redraw them as needed in the right order. Let's say each element is a roAA (contains x,y,h,w,img and other things it may need). Such elements would be added and removed dynamically. Adding is easy - but for removal when i say
Manager.remove(A), it should be able to enumerate its bag and find "by reference" the element in question, then remove it. But that is not possible currently.
My request is, when comparing for equality 2 objects of the same* type: "
A = B" should return
True if A and B are the very same object (i.e. references are equal) and
False otherwise.
Alternative approach would be to add a global function
id(obj), that given an object, returns an integer. Typically (and simplest) is for that int to be the memory address of the object as a number - but the relevant/guaranteed part is that if id(A) = id(B), then A and B are the
very same object (and vice versa, the relation is if-and-only-if).
(*) What should happen when trying to compare 2 objects of different type (e.g. "
if { } = [ ] then ...") may vary. It may (a) be left with the current "Type Mismatch" error or (b) it may simply return False, since the two objects are not identical (the 2 memory references differ, a check as brutal as that). And by "objects" here i mean any boxed (non-intrinsic) type.