A good way to learn this is using the Open Event, so during the instance initialization it has the opportunity to add itself to the shared array and also to set its own index value. We also need to know in runtime how many instances we are using. For this, nothing works better than setting a new Property (this time, a regular or instance Property) and assigning its data type as Integer: Of course, we need a way to reference every instance created from the class for example, when we need to send a message to only one of them and not to all the available instances. That means that this will be visible only from the code executed inside the class. The fact that this is a Shared Property means that it (and its stored values) will be available for all the class instances (objects) created from the class while the regular properties allows us to store distinct values for each class instance.Īnother detail is that, in this case, we have limited the Scope for the Shared Property to Private. With the created class still selected, add a new Shared Property from the Insert menu and use the Inspector with the following values: For this, nothing is better than adding a Property to our class whose data type is an array storing objects from our class. Next, we will need a data type acting as a storage reference for every instance (in our example, buttons) we want to add to our UI layout. ![]() (Obviously, you can change these for any others you need.) Creating an array to keep references to the instances ![]() For this example, use the following values: All of this without knowing in advance, at runtime, how many of such instances are placed in the layout.Īn inconvenience of this feature is that you can’t use it when the graphic controls are placed on a ContainerControl due to the way ContainerControls are implemented. The good news is that this problem has an easy solution! Read on to learn about it:įirst, create subclasses from those Framework controls you want to use as a Control Set this also applies when creating your own graphic controls from scratch.įor that, add a new Class to a Xojo project from the Insert menu and use the Inspector to set the class name and the Parent class it is derived from. For example, this allows us to invoke a method in a concrete instance, based on its control index, or invoke the same method to all of them (iteration).
0 Comments
Leave a Reply. |