![]() ![]() When we use the assignement operator (=) to set the values (items) of an Array to another one, what in fact happens behind the scenes is that the target Array will store only a reference to the source Array (the right-side value of the assignement operator), and not a copy of the values/objects stored. That is, in practice we will be emptying the Array.Īs result of this operation you could expect that, while the contents of the ASource() variable are emptied, your ATarget() Array will continue storing their items. ![]() In this case we will be redimensioning the storage capacity of our ASource() Array with a total of 0 items. However, what happens if we add the following line of code at the end of our fragment of code?: ASource.ResizeTo(-1) (Navigate through the Debugger Inspector Panel to inspect these variables) If you set a breakpoint in the last line of code and execute your test app, then you’ll see that, as exepected, the contents of the ATarget() Array are the same that the ones stored by the ASource() Array. Try to write the following fragment in the Opening Event of a new Xojo Project or Method created by yourself (don’t forget to call such method, if you decide to follow that path): Var ASource() As Integer = Array(1,2,3,4,5,6,7,8) Of course, and at a first glance, this is the case. In this case, it’s also probable that you might be confused at first as to why you don’t get what you expected when assigning the contents of a source Array to a target Array via the assignment operator (“=”).Īfter all, when using the following snippet of code we could (wrongly) expect that the contents stored in the ATarget Array would be the same that the ones stored in the ASource Array. If you’re starting to program with Xojo, then you’ll probably soon find yourself in a situation where you need to use one of the Container types: Array.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |