<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Casey Ransberger wrote:
<blockquote cite="mid:2CE4FF40-35D5-491E-8366-AD89463C4CC2@gmail.com"
 type="cite">
  <pre wrap="">Maybe worth noting that #storeString might not work so well with a Morph that's visible in the World... IIRC that ends up trying to store the whole World, because Morphs hang onto a reference to their current World.

It will work as long as there aren't cycles and it's not in the current world.

In the menu of a workspace, there's an option to create references from dropped Morphs. I think the way I hustled around the problem was by dropping my handmade Morph into the workspace to get a reference, then detaching the Morph from the world with the halo (the workspace has a reference so the Morph doesn't meet the great garbage collector in the sky.)

#storeString and #storeOn: are fun:)

On Jun 9, 2012, at 2:37 PM, Chris Cunnington <a class="moz-txt-link-rfc2396E" href="mailto:smalltalktelevision@gmail.com">&lt;smalltalktelevision@gmail.com&gt;</a> wrote:

  </pre>
  <blockquote type="cite">
    <pre wrap="">Well, I don't think you'd programmatically create a new class, because your instance has to have been an instance of a class that already exists. Or else you would not have an instance to begin with. 

Perhaps, you want a way to programatically reproduce an instance you've been working with by hand in a Workspace. You have the instance. It's just right. You want it to be programmatically reproducible at will. I'd use Object&gt;&gt;storeString. 

x := (HelloWorld new) color: 'Black'.

I've created a instance with an instvar. I send it storeString:
        
x storeString 

and I get: 

'(HelloWorld basicNew instVarAt: 1 put: ''Black''; yourself)'

It's a bit crufty to me. I remove the first and last quote and parentheses. The double single quotes aren't great, so I remove them too. 

HelloWorld basicNew instVarAt: 1 put: 'Black'; yourself

Print it, and get: 

a HelloWorld 

I'm not sure why it comes in some extra syntax. 
That's my best guess at an answer to your question. YMMV. 


Chris 




On 2012-06-09, at 5:04 PM, Erich Groat wrote:

    </pre>
    <blockquote type="cite">
      <pre wrap="">Hi all,

I was wondering if there are any built-in facilities for taking a particular instance a class X, call it anX, and creating from it a class method that returns an identical instance of anX for future use.

For example, say I'm futzing around in a workspace with an instance of a class called InteractiveWindowShape, tweaking things so that I have a nice window with all the colors and proportions and buttons I want, perhaps using Morphs to create the thing dynamically (so it's some kind of Morph object). In the course of this I get an instance of anInteractiveWindowShape that I am satisfied with, all the instance variables set just right. Let's call this object | idealShape |. It's just sitting there, rather vulnerably, in a workspace, the result of my using various screen tools over the last half hour. Now, I don't just want to save this object: I want to be able to create an identical one whenever I like. So what I want is a Class method, InteractiveWindowShapes class&gt;&gt;newIdealShape, that creates an instance exactly like idealShape.

Is there a message I can send to this instance idealShape that would return a block of code that would act as a class method, which I could then call newIdealShape, and which would return an identical instance?

I suspect such a general method might not exist, due to the potential hazards surrounding the deep copy problem; I also suspect I may not be imagining the best sort of solution to my problem. Is there a strategy for this?

Thanks all!

Erich
_______________________________________________
Beginners mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Beginners@lists.squeakfoundation.org">Beginners@lists.squeakfoundation.org</a>
<a class="moz-txt-link-freetext" href="http://lists.squeakfoundation.org/mailman/listinfo/beginners">http://lists.squeakfoundation.org/mailman/listinfo/beginners</a>
      </pre>
    </blockquote>
    <pre wrap="">_______________________________________________
Beginners mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Beginners@lists.squeakfoundation.org">Beginners@lists.squeakfoundation.org</a>
<a class="moz-txt-link-freetext" href="http://lists.squeakfoundation.org/mailman/listinfo/beginners">http://lists.squeakfoundation.org/mailman/listinfo/beginners</a>
    </pre>
  </blockquote>
  <pre wrap=""><!---->
  </pre>
  <pre wrap="">
<hr size="4" width="90%">
_______________________________________________
Beginners mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Beginners@lists.squeakfoundation.org">Beginners@lists.squeakfoundation.org</a>
<a class="moz-txt-link-freetext" href="http://lists.squeakfoundation.org/mailman/listinfo/beginners">http://lists.squeakfoundation.org/mailman/listinfo/beginners</a>
  </pre>
</blockquote>
You might look at Class Variables.&nbsp; Use the halos to bring up an
Inspector on the top level morph, and within that execute MyClass
storeProtoype such that you store the morph you have.&nbsp; Then later work
out how you want to copy generate clones of that object.&nbsp; For example<br>
<br>
MyClass class &gt;&gt; storePrototype: aMorph<br>
&nbsp;&nbsp;&nbsp; MyClassVariable := aMorph.<br>
<br>
<br>
MyClass class &gt;&gt; clonePrototype<br>
&nbsp;&nbsp;&nbsp; ^ MyClassVariable copy.<br>
<br>
Also, you might look back at Squeak 3.9 and go...<br>
1. World &gt; Flaps &gt; Supplies<br>
2. The drag your morph into the Supplies flap which should now show a
icon looking like you morph.<br>
3. Now drag several of those icons out into the world.<br>
<br>
cheer -ben<br>
</body>
</html>