Hi Marko,

How are things in Finland?  I hear it is nice there and there seems to be a
bit of a marketing campaign to get Americans to visit.

Anyway let's get to your question.  There are a number of ways to pass
variables around.  The least effective way is to call methods with a lot of
parameters.  Usually when I see methods with lots of parameters there is a
problem and the problem most likely is that the methods is implemented in
the wrong class.  

Consider for a moment an example (since you asked for code examples)

Object subclass: Car

Object subclass: Engine

Object subclass: Fuel

Object subclass: Spark

Now we all know that for engine it run it needs Fuel and Spark so we could
model the car so that it has each 

Car
        instanceVariables: 'engine fuel spark'

Then we have 

Car>>start
        "Start the car"
        self engine startWithFuel: self fuel andSpark: self spark onCar:
self

Engine>>startWithFuel: someFuel andSpark: someElectricity onCar: aCar
        "run the engine"
        [someFuel notEmpty] whileTrue: [
                movement := someFuel burnFuelWith: someElectricity
        ].
        aCar addMovement: movement

Car>>addMovement: someMovement
        "handle the movement of the engine through a transmission"
        self transmission handleMovement: someMovement

Ok so now I'm just amusing myself and thinking of the car being in idle so
not using the fuel to move at all, wasting gas and promoting global warming.


Getting back to your question what would happen instead if we have the
parameters modeled where they are needed.  Ask yourself does the car need
gas and fuel or does the engine need it instead?

So 

Car
        instanceVariables: 'engine'

Engine
        instanceVariables: 'fuel spark transmission car'

Now when we build the objects we get much less parameter passing.

Car>>start
        "start the car"
        self engine start

Engine>>start
        "start the engine"
        [self fuel notEmpty] whileTrue: [
                movement := self fuel burnFuelWith: self spark
        ].
        self transmission addMovement: movement

Now this was a long answer to your question and you may be sitting there
saying; "What does this have to do with databases and buttons"!

Well if you model your parameters in objects they don't need passing.

TestDatabase
        instanceVariables: 'dataSource user password myDBConnection'

Then your button's method #executeTest
        
TestDatabase>>executeTest
        self myDBConnection on: self dataSource logon: self user password:
self password.

Where dataSource can have host and port and dbname ...

I hope this helps for specific examples you could try
http://www.google.com/search?hl=en&q=mysql+squeak 

If this doesn't make sense, feel free to ask questions.  Let me know how it
goes!

Happy coding!

Ron Teitelbaum
President / Principal Software Engineer
US Medical Record Specialists
[EMAIL PROTECTED] 



> From: Marko Koivuniemi
> Sent: Monday, June 05, 2006 4:14 PM
>
>
> Greetings from Finland. I am very excited about Squeak and SmallTalk - I
> have find myself trying and exploring new programming things and that
> hasn't happen since days of Commodore 64.
> 
> Now I am trying to build (with one partner) a program which uses MySQL.
> I wonder what would be best way to do login screen and actual program.
> 
> Now we have morphs in windows which has login and password fields and
> button. At this time idea is that this startup screen test login
> information and then sends user (or user id) to another screen.
> 
> I tested various styles and this kind of test "works" with button.
> 
> test := DatabaseTest new.
> loginbutton := MyButtonMorph new send: #executeTest to: test";
>    openInHand".
> 
> But what would be the best way to send many variables or values with
> button click. (I have couple TextFieldMorphs storing values)
> 
> I have googled a lot - and most examples deals scriptable buttons. (And
> that is something I am not familiar with - as a novice I must see code
> and try different things and see what's happening...)
> 
> 
> --
> Marko
> _______________________________________________
> Beginners mailing list
> Beginners@lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners

Reply via email to