Duplicating a class in the IDE

I submitted this as a bug (<https://xojo.com/issue/50844>) and it was closed as by design. This has to be bug, right or am I just crazy? I’m seeing this in OS X, 2017r3.

  1. Create a class, name it “original”, set the super class to bevelbutton.
  2. Add a property to this class, in my case I added the text property “key” with a default value of “original”
  3. Add the action event handler, set the code to msgbox(me.key)
  4. Duplicate this class in the IDE (ex: cmd-d), rename it “duplicate”
  5. Change the default value of “key” in this duplicated class to “duplicate”
  6. Drag an instance of both the original and duplicated classes to a window and run
  7. Click the buttons

One msgbox should say “original” and the other should say “duplicate”, right? I get “original” for both of mine.

No. Not a bug. When you “duplicate” an object (a class is an object) you are pointing to the same memory. You don’t have 2 distinct classes. You only have one as you discovered.
Don’t duplicate your class. If you want a new class to inherit from the original, then create a subclass. Otherwise, just create a NEW class.

So you’re saying that duplicating a class in the IDE does not in fact give you a new class? And even though you look at the default value of a property of that class and it says, “duplicate”, but when you run it it says “original”, that’s not a bug?

precisely.

I did exactly this

and it worked like YOU expected it to

So either I misunderstood what you said, or you did something different

What Roger is refering to is INSTANCES of the same control
What you are describing is creating TWO distinct but similar classes…
the Duplicate YOU are creating makes a new control class
what Roger is referring to, is a new class INSTANCE

I am duplicating a class in the IDE. I am not, in code, creating 2 instances of a class and expecting them to behave differently.

Thanks, Dave, for giving me the benefit of the doubt, :slight_smile: but I thought I was correct that “duplicating” a class would still refer to the same class. Apparently, I was wrong. Some experimentation on my part is in order.

That is inaccurate. What you describe is what happens when you do myobject1 = myobject2 in code. Duplicating a class in the IDE creates a copy of the class as it was at the time of duplication.

This whole thread is just confusion over values stored by instances of objects in the IDE. If you turn on the “msg” property with the Inspector Behavior you can see that both instances from the original feedback case have the same msg value.

and based on your steps… they DO act differntly, because they are totaly unique objects
NOT two controls based on the same object

I’ve been able to have these consistently behave as if they were identical classes with about 4 new projects. I can save them as XML and see that the class definition holds one default value while an instance is created with a different default value. Now what’s causing the disparity between yours and mine I have no idea.

Order of operations. If you instantiate it on the window before making a change to the superclass, that change does not propagate to the instance that exists on the window already.

Edit: wording for clarity

For help, here’s the exact project from feedback with the msg property turned on in the Inspector Behavior:
https://www.dropbox.com/s/gyvtvxi6cz3mcfv/instances_example.xojo_binary_project?dl=1

I had to change the name because I already have a test.xojo_binary_project in my Dropbox.

I created my original class, duplicated it and change the default value on the duplicate before dragging instances of either class to a window.

Here’s a test project that shows that it works as it’s supposed to:
https://www.dropbox.com/s/y2pnvmxc2zce49l/buttons_classes_test.xojo_binary_project?dl=1

I have turned on the custom property in the Inspector Behavior in this project as well so you can see in the IDE the difference between this project and yours. Both instances on yours have the same msg value. I can only guess at your order of operations, but the msg value is where the confusion is.

You are even able to change the msg value in the original test project to see the desired results.