Getting Rid of a Control Group

Hey all,

I’ve got an object that I have in a control set on a container control. I have it instantiated in the IDE on the page, so I can more easily access my events and so forth without using a bunch of AddHandler Statements (which I could do).

So I’ve discovered I have a situation in some circumstances where I need to completely remove all the controls from the control set and recreate them later. But as my object is not subclassed from control, there is no “close” method. I have a method where I basically unhook and tear down the control but even though I call that, the framework does not remove the object from the control set.

How can I eliminate the object from the control set? You can’t use normal array methods like “remove”, etc. Trying to do something like:

MyControl(i) = Nil

Doesn’t work either. I get a compiler error.

If I have to, I’ll go back to completely instantiating everything in code. It’s just a couple of methods, but so much easier to not have to deal with the AddHandlers when I don’t have to.

I feel like I should know how to do this but I don’t. It works fine with an object subclassed from Control, but not objects.

Try :
MyControl(i).Close

[quote=164761:@Karen Atkocius]Try :
MyControl(i).Close[/quote]

You didn’t read my post very closely did you? :slight_smile:

Only objects subclassed from Control have a Close method.

I’m not subclassed from control as sometimes I need to instantiate my object purely in code.

What do you mean ? I created a bunch of buttons in a control set in the IDE, and now I can remove them at run time with pushbutton(n).close. Just tested. Or I missed something ?

[quote=164765:@Jon Ogden]ou didn’t read my post very closely did you? :slight_smile:

[/quote]
Control sets have to be composed of controls so they do have close methods… so I have no idea what you are talking about!

  • karen

Ugh. Please read.

A button is subclassed from control. Therefore, it HAS a close method. And calling close works to remove it from the control set.

My object is NOT subclassed from control.

[quote=164771:@Karen Atkocius]Control sets have to be composed of controls so they do have close methods… so I have no idea what you are talking about!

  • karen[/quote]

No, they don’t. Create an object that does not have a super, and drop it in a window in the IDE. You now have an object in the bottom line of the IDE that looks like a circle with a flower inside it. The Super of this instantiated object is your object. Now create a control set by clicking on the gear and selecting “Create new control set.”

Now, your object does not have a close method.

How do you remove items from the control set??

I don’t think what you are doing is supported…

While this is not supported either… try setting it’s super to control or RectControl… IIRC at one time some years ago the IDE would let your do one of those things and it seemed to work, but I never had a use for that so sis not see how well it worked.

If it works, then you will have a close method…

  • Karen

[quote=164776:@Karen Atkocius]I don’t think what you are doing is supported…

While this is not supported either… try setting it’s super to control or RectControl… IIRC at one time some years ago the IDE would let your do one of those things and it seemed to work, but I never had a use for that so sis not see how well it worked.

If it works, then you will have a close method…

  • Karen[/quote]
    Ack! What do you mean it’s not supported? Of course it is. It works just fine. If you have an object with events and you want to be able to implement those handlers in the IDE, then this is how you’d do it. Try creating a control set of timers. A timer does not have have a close method. It’s not subclassed from control. So how would you remove a timer from a control set?

I already explained in my original post why I didn’t make my object a subclass of control. If you do, then you can’t implement that object 100% in code.

So can anyone give me anything meaningful?

Is there any reason you could not just make this things super Control (not RectControl)
I expect doing that would make this all work with not extra magic required
BUT you may then be back to not being able to create them purely in code

[quote=164781:@Norman Palardy]Is there any reason you could not just make this things super Control (not RectControl)
I expect doing that would make this all work with not extra magic required
BUT you may then be back to not being able to create them purely in code[/quote]

Exactly. I want to be able to have the option to instantiate them in code.

I use this object in three different apps and want the flexibility.

So forgetting my object, how would one remove a timer from a control set of timers.

One you manually created in the IDE ?

Yes. So same
Issue with a timer. Let’s say you create a control set of timers. How would you remove a timer from the control set?

Usually, the easiest way to remove a timer is simply not to drag it over a window, but to initiate it in code and let it go out of scope.

No kidding.

Roll with me here. It’s a valid question and a weakness in the IDE/Framework.

You have a control set of timers or sockets or whatever that is not subclassed from control that is in a control set. How do you remove one of those items from a control set?

You have a control set of serial objects or TCP sockets. How do you remove one of the members of the control set? The close methods on these objects don’t destroy the objects but instead close the connection.

So there must be an answer. Or perhaps the programmers at Xojo are saying, “Oops!” right now.

Since they’re not controls they have no close method you can call
Pretty sure you wont be able to
A quick trial confirms that

And a quick trial suggests that a control set of custom classes that have Control as their super are also not “closable”

I would personally create a factory method which creates a new object, hooks up all of the AddHandlers and adds it to an array. Then you create a destroy method which does RemoveHandler and then removes the instance from your array. I’ve never considered using non-controls in a control array since the name does imply that it is made up of controls… Maybe the fact that the IDE allows you to create a control array out of non-controls is a bug? I have no idea.

I don’t know the reason for the control set, but it seems from a quick experiment that timers as well as classes with no super can be put in dictionaries. It is not quite the same as control sets regarding events, but using addhandlers one could point to one method for each, a bit like we do in iOS to emulate control sets.

And dictionary keys can be removed.

Not a bug but then you also lose some control :stuck_out_tongue:
And since these are not “controls” a control set ties Jon’s hands more than it seems to help since now he cant get rid of them.

Maybe you guys should change the name again. Something like “object set” this time, since they don’t have to be controls :stuck_out_tongue: