Transferring variable values to another image

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Transferring variable values to another image

DougEdmunds
I created a class that uses a classVariable.  How can I export
the contents of that variable to an external file so I can import it
back into another image after I filein the class to the other image?

Thanks.

-dae
Reply | Threaded
Open this post in threaded view
|

Re: Transferring variable values to another image

Stéphane Ducasse

On Mar 15, 2011, at 8:42 AM, DougEdmunds wrote:

> I created a class that uses a classVariable.  How can I export
> the contents of that variable to an external file so I can import it
> back into another image after I filein the class to the other image?

nothing is done by default.
You should define it in an initialize.

>
> Thanks.
>
> -dae
>
> --
> View this message in context: http://forum.world.st/Transferring-variable-values-to-another-image-tp3355928p3355928.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>


Reply | Threaded
Open this post in threaded view
|

Re: Transferring variable values to another image

Andrew Black


> On Mar 15, 2011, at 8:42 AM, DougEdmunds wrote:

 > > I created a class that uses a classVariable.  How can I export the
 > > contents of that variable to an external file so I can import it back
 > > into another image after I filein the class to the other image?

 > nothing is done by default.
 > You should define it in an initialize.

Yes, you need to write an initialize method on a class that initializes the class variable.  
When you load a class into your image, an initialize methods on the class side
is executed by the loading machinery.

Another question is whether you really want a class variable or a class instance variable.  I'll leave that for you to decide.

     Andrew

Reply | Threaded
Open this post in threaded view
|

Re: Transferring variable values to another image

Paul DeBruicker
In reply to this post by DougEdmunds
On 03/15/2011 07:02 AM, [hidden email] wrote:

> From: DougEdmunds<[hidden email]>
> Subject: [Pharo-users] Transferring variable values to another image
> To:[hidden email]
> Message-ID:<[hidden email]>
> Content-Type: text/plain; charset=us-ascii
>
> I created a class that uses a classVariable.  How can I export
> the contents of that variable to an external file so I can import it
> back into another image after I filein the class to the other image?
>
> Thanks.
>
> -dae


Couldn't SIXX be used for this?


http://www.mars.dti.ne.jp/~umejava/smalltalk/sixx/index.html




Reply | Threaded
Open this post in threaded view
|

Re: Transferring variable values to another image

DougEdmunds
In reply to this post by Andrew Black
Let me change the scenario a little, using a class instance variable.

1. start with two clean images, image1.image and image2.image.

2. install the Contact Manager classes from
http://www.pharocasts.com/2011/02/pharo-gui-with-polymorph.html
into image1.

3. run the program "ContactListEditor open" and populate the database
with some entries,  i.e., "Fred Flintstone", "Barney Rubble", "Wilma Flintstone".
Those entries are stored in the Contact class instance variable 'database'.  

4. fileout the Category "Contact Manager" from image1.image.

5. open image2, and filein "ContactManager.st".

6. run "ContactListEditor open" in image2, the database is empty.

How do I transfer the contents ("Fred Flintstone", "Barney Rubble",
"Wilma Flintstone") stored in the Contacts class instance variable "database"
from the image1 into image?  

Reply | Threaded
Open this post in threaded view
|

Re: Transferring variable values to another image

laurent laffont
On Tue, Mar 15, 2011 at 5:42 PM, DougEdmunds <[hidden email]> wrote:
Let me change the scenario a little, using a class instance variable.

1. start with two clean images, image1.image and image2.image.

2. install the Contact Manager classes from
http://www.pharocasts.com/2011/02/pharo-gui-with-polymorph.html
into image1.

3. run the program "ContactListEditor open" and populate the database
with some entries,  i.e., "Fred Flintstone", "Barney Rubble", "Wilma
Flintstone".
Those entries are stored in the Contact class instance variable 'database'.

4. fileout the Category "Contact Manager" from image1.image.

5. open image2, and filein "ContactManager.st".

6. run "ContactListEditor open" in image2, the database is empty.

How do I transfer the contents ("Fred Flintstone", "Barney Rubble",
"Wilma Flintstone") stored in the Contacts class instance variable
"database"
from the image1 into image?


One way is to use a database. You can try SandstoneDB http://www.pharocasts.com/2010/04/sandstonedb-simple-activerecord-style.html

Laurent.

 
--
View this message in context: http://forum.world.st/Transferring-variable-values-to-another-image-tp3355928p3357111.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: Transferring variable values to another image

Mariano Martinez Peck


On Tue, Mar 15, 2011 at 5:49 PM, laurent laffont <[hidden email]> wrote:
On Tue, Mar 15, 2011 at 5:42 PM, DougEdmunds <[hidden email]> wrote:
Let me change the scenario a little, using a class instance variable.

1. start with two clean images, image1.image and image2.image.

2. install the Contact Manager classes from
http://www.pharocasts.com/2011/02/pharo-gui-with-polymorph.html
into image1.

3. run the program "ContactListEditor open" and populate the database
with some entries,  i.e., "Fred Flintstone", "Barney Rubble", "Wilma
Flintstone".
Those entries are stored in the Contact class instance variable 'database'.

4. fileout the Category "Contact Manager" from image1.image.

5. open image2, and filein "ContactManager.st".

6. run "ContactListEditor open" in image2, the database is empty.

How do I transfer the contents ("Fred Flintstone", "Barney Rubble",
"Wilma Flintstone") stored in the Contacts class instance variable
"database"
from the image1 into image?


One way is to use a database. You can try SandstoneDB http://www.pharocasts.com/2010/04/sandstonedb-simple-activerecord-style.html


Or any object serializers, like SIXX (in XML), ReferenceStream and friends (this are even in PharoCore), ImageSegment, etc...
Another common strategy is to store them in kind of code:

users
    add: User name: 'Mariano';
    add: User name: 'you';
....

 
Laurent.

 
--
View this message in context: http://forum.world.st/Transferring-variable-values-to-another-image-tp3355928p3357111.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.



Reply | Threaded
Open this post in threaded view
|

Re: Transferring variable values to another image

Sean P. DeNigris
Administrator
In reply to this post by DougEdmunds
For your simple case, I would use ReferenceStream. It's really easy, just check out the class comment. I've used this to move all the data for a Pharo app from one image to another, it's pretty cool.

Sean
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Transferring variable values to another image

Scott Gibson
Thanks Sean!  I am new to Smalltalk and that just helped me with a quick and simple solution for the moment.

On Mar 16, 2011, at 5:42 PM, Sean P. DeNigris wrote:

> For your simple case, I would use ReferenceStream. It's really easy, just
> check out the class comment. I've used this to move all the data for a Pharo
> app from one image to another, it's pretty cool.
>
> Sean
>
> --
> View this message in context: http://forum.world.st/Transferring-variable-values-to-another-image-tp3355928p3383109.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>


--
Scott Gibson
[hidden email]