Anthony’s interpretation may be correct, but as a rule, when asking questions on the forum try and be as specific as possible. “My app throws me away” is not specific. If there is an error message, you want to specify what it is, and when you see it. Basically be explicit as possible as to what happened.
You do have to go through all the elements in the Dictionary that are specifying Object2D’s on your canvas. Anthony is suggesting one sophisticated methodology to try and organize and possibly speed things up. I would emphasize that going through all the Object2D’s in a Dictionary is actually quite speedy and I would not be too concerned about using possibly more “optimal” solutions at an early stage of trying to understand Xojo canvases. To a human, it would seem unbelievably inefficient to redraw 20 items when you have just changed one of them. But for this task, Xojo is so efficient that I would not worry about it.
There is a concept in programming of “premature optimization”. First get the code to work with the easiest approach. Then decide if you want to optimize. With this particular issue, I suspect that you will find that redrawing “everything” with each Paint Event is so fast that it will not bother you.
The code I posted is not optimal, nor is it prematurely optimized. It is, in my opinion, a solid base for the task that the user can easily build upon. I’m not saying your method is wrong, but – having done this a time or two – I know I’d probably end up rewriting the mechanism you outline at some future point. Whether that be out of necessity or OCD, it’s hard to say, but I know I’ve done it that way and eventually thought to myself “No. No, that has to go.”
When using it I had a “NilObjectException” message.
You absolutely read my mind
Sorry but why do I have to instantiate MyDICTION which is a Property (MyDICTION as dictionnary) as when I use another property like mX as integer I can access it directly?
Because some datatypes like DateTime
, Timer
and Dictionary
require instantiation.
Other datatypes like String
, Integer
, Double
, Boolean
, etc. are primitive datatypes, which do not.
Keep in mind, any kind of object (primitive & non-primitive) can be assigned as a datatype to a property, including custom Classes.
Regardless of whether a non-primitive object is assigned as a local variable or a property, it will almost always require the New
keyword (instantiation). There a few exceptions, such as DateTime.Now & DateTime.FromString that come to mind.
Those are functions. That’s why. The DateTime is instantiated inside the function for you.