New PushButton does not work

I am trying to understand the whole concept of creating a new instance of a control with the “New” instruction.

I tried the following example described in the manual, but I get “there is no class by that name”. PushButton1 does exist, I am trying this from its Action event, as described. What gives ? Is there a bug in the manual, or am I missing something ? TIA

This example creates a new instance of a pushbutton called “Pushbutton1” then sets its caption. Add a PushButton to a window and name it PushButton1. Set its Index property to zero, making it the first element in a control array. Set its Caption property to “Original”.
In its Action event, create a clone of the pushbutton and enter this code
Dim pb As PushButton
pb=New pushbutton1

When you run the application and click the pushbutton, it creates a new pushbutton to its right that is the second element of the control array. You can tell by its caption that it is the new pushbutton that was created in the Action event of the original PushButton.

This is strange…I just launched xojo 13r3 & placed a push button on a blank window, but for the life of me I can’t find where to set Index property?

It’s not in the ID/inspector panel…where is it?

Looks like the Language Reference needs a little updating regarding that. With Xojo you create a “Control Set” to do this. Refer to User Guide Book 2: User Interface, Chapter 2: Desktop, Section 16: Control Sets and Dynamic Controls.

Thanks Paul,

Now can’t find away to add a control set via docs [quote]To create a new Control Set, choose New Control Set from the popup menu. This creates a Control Set with the name of the selected control.[/quote]

There’s no new “New Control Set” option in the popup menu…anyway, shouldn’t this be in the inspector panel?

[quote=45156:@Kuzey Atici]

There’s no new “New Control Set” option in the popup menu…anyway, shouldn’t this be in the inspector panel?[/quote]

If you click on an object you drag in from the library it will have “Control Set” with a Popup menu that says “Member of None” in the inspector. If you click on “New Control Set” there you should get what you want. It might look like nothing happened but if you look on the list at the left there will be a set with the first object having the zero index as expected. It took me a little bit to figure out when I moved from RS to Xojo.

Thanks Jason, I see it now.

For some reason I was thinking contextual menu :slight_smile: