Creating a visual part that contains a variable
Create a new visual part called RunnerDataView in the same application as your RoadRaceView visual part. Use push buttons, labels, text, and list parts to make the window part look like the one in the previous section. When you've completed the window part layout, connect the clicked event of the Cancel push button to the closeWidget action of the window part.
Adding the variable
A variable acts as a placeholder, where a real part can be substituted later. We are using a variable instead of an actual part because we don't know what the actual part should be when the window part is first created.
Select the Models category from the parts palette, and then add a Variable part, to the free-form surface. Change its name to runner.
Tip icon
Notice the square bracket symbols around the variable part. You can identify a variable by these symbols. Also note that tear-off attributes also have square brackets and are in fact variables with a special connection.
Changing the variable's type
When you add a variable part, its type is initially Object, meaning that the variable can stand for any object. Because the object is really a Runner part for this example, select Change Type on the Variable part's pop-up menu, and change its type to Runner.
Notice that the Variable part's attributes now match those of the Runner part you created earlier. Connect the Variable part's number attribute to the object attribute of the Runner number Text part, and then connect the Variable part's finishTime attribute to the object attribute of the Finish time Text part.
The connections should look like the following:
Connections
Making the variable public
So far, the Variable part has been prepared to hold a Runner object, but the Variable part is still empty. The runner we want comes from RoadRaceView, the visual part we created earlier, in Creating a reusable visual part.
To make the Variable part available to RoadRaceView, or to any visual part, we need to add the Variable part to the public interface of RunnerDataView. Do this by selecting Promote Part Feature from the Variable part's pop-up menu. Select self from the attribute list. Notice the Promote feature name text object shows runner which is derived from the part's name. Select the Promote push-button and then OK to promote this feature to the visual part's public interface.
Now any other part that uses this part can provide an instance of a Runner part that can be displayed in the RunnerDataView window.
Save and close your visual part.
Last modified date: 07/16/2020