Do you really need to create a meta? If not , then you can do just: newClass := Rectangle clone. newClass superclass: Rectangle; organization: nil; methodDict: MethodDictionary new. On 23 May 2010 15:49, Joachim Geidel <joachim.geidel@onlinehome.de> wrote:
Hi everybody,
I am attempting to create subclasses of existing classes at runtime. They must not be in their superclass' list of subclasses, because they have to be garbage collected when they are no longer needed.
This is what I tried to create such a class in Pharo 1.0:
  newMeta := (Metaclass new)     superclass: Rectangle class       methodDictionary: MethodDictionary new       format: Rectangle class format;     yourself.   newClass := (newMeta new)     superclass: Rectangle       methodDictionary: MethodDictionary new       format: Rectangle format;     setName: #MyRectangle;     yourself.   newClass new class == newClass  "--> false"
The result of "newClass new" seems to be an instance of Rectangle, not of newClass. The test at the end of the code snippet answers false. When I compile a new method in newClass and install it in newClass' methodDictionary, an instance will not understand a message with the method's selector.
Almost the same code will do what I want in VisualWorks:
| newMeta newClass |  newMeta := (Metaclass new)     superclass: Rectangle class;     methodDictionary: MethodDictionary new;     setInstanceFormat: Rectangle class format;     yourself.   newClass := (newMeta new)     superclass: Rectangle;     methodDictionary: MethodDictionary new;     setInstanceFormat: Rectangle format;     setName: #MyRectangle;     yourself.   newClass new class == newClass  "--> true"
Does anybody have an idea what the problem is and what can be done to circumvent it?
Thanks in advance! Joachim Geidel
_______________________________________________ Pharo-users mailing list Pharo-users@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-users
-- Best regards, Igor Stasenko AKA sig.