TOPIC: Arguments for Controls
#1436
Arguments for Controls 1 Year ago
I have question about using arguments inside Controls declaration, if I make controls like this:

class
{
Name:some_name
New()
{
...
}
Controls: (Horz (Button 'one') (Button 'two') )
}

then I can not pass argument to controls like this: (Horz (Button arg1) (Button arg2) ) I have to use different way for this. No problem but i thinking way is there no argument possible?
 
 
#1437
Re:Arguments for Controls 1 Year ago
You can pass arguments, but inside a constant, you can only use constant values (not variables). Class definitions (including their members) are constants.

There are several ways to pass variables:

In a Controller, you can do:

Code:

New(...)
    {
    super(Object('Button' arg))



or for long definitions you can extract to a method:

Code:

New(...)
    {
    super(.controls(...))
    }
controls(...)
    {
    return Object('Button' arg))
    }



or if you do not need any arguments from New, you can just make Controls a function:

Code:

Controls()
    {
    return Object('Button arg))
    }



I hope that helps.
 
 
andrew
 
#1440
Re:Arguments for Controls 1 Year ago
Thank you. Changed it already works ok. why are the class readonly?
 
 
#1441
Re:Arguments for Controls 1 Year ago
There are several reasons.

Library definitions are constants - they are compiled - nothing is run at compile time.

I think self-modifying code makes programs hard to understand. I think it is simpler (and better) if you can look at a class definition and know that "what you see is what you get" - that nothing will be changing it "on the fly".

Other languages, such as Ruby, take a different approach and use a lot of run-time modification of code.
 
 
andrew
 
#1442
Re:Arguments for Controls 1 Year ago
OK, i see. I used work with Python/Ruby :ohmy: will take time for change thinking. Thank you!