electronicsgogl.blogg.se

Xojo properties
Xojo properties









For our testing app, we also need an additional PushButton (it can be one from the standard Library) and a TextField. For this, drag and drop as many instances of the class as you want from the Navigator to the Window Layout Editor (select previously a Window!).

#Xojo properties code

Next, write the following line of code in the Code Editor for the Shared Method: if ClassButtons.ubound -1 and index >= 0 and index <= ClassButtons.Ubound then MsgBox ClassButtons(index).Caption Testing the Class So, add a new Shared Method to the class using the following values in the associated Inspector: For this example, we are going to display a simple message whose content is the Caption set to the button index passed as parameter and that has been created from our class.Īs is the case with the Shared Properties, the Shared Method is the resource provided by the Xojo language that lets us set a behavior for the Class itself, instead of being called from a concrete class instance. In order to see our example in action, we need to create a method letting us direct the available instances to do something.

xojo properties

This way, RaiseEvent Open will call the Open Event to the instance and will let our class user write and execute additional code during the control initialization. What does RaiseEvent Open mean? Notice that we are setting our class behavior so if we are using the Open Event on it, this Event will not be available for implementation for any of the instances created from the class.įixing this is really simple: add a new Event Definition to the class using the following values in the associated Inspector: To do that, add the Open Event Handler to the class and write the following snippet of code in the associated Code Editor: Sub Open() Handles Open 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:

xojo properties xojo properties

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

xojo properties

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). A Control Set is the feature to use when there are several instances in a Window’s layout and you need to command (or access them) from code, both for those available by default in the Framework and ones based on your own graphic classes.









Xojo properties