TOPIC: How to adress controls
#883
How to adress controls 3 Years, 3 Months ago
I'm just a beginner in Suneido and I'm not a good programmer (though I've developed a couple of relatively big applications on MS Access). User's Manual have not much info so I don't understand completely some things. First: how to adress controls?

Using standart Example from User's Manual (library mylib, see also Going Further-> Master-Detail Relationship), I have slightly modified 'My_EnterInvoices' (add a button for experiments while I am studying Suneido). What I want: after pressing a button Alert appears which contains the value of some field. I've found that Get method is used for that but I can't name the control.

Code:


Controller
{
Controls:
(Access
title: "Enter Invoices"
invoice
(Vert
(Horz invoice_number Skip customer Skip invoice_main)
Skip
(Button "Test"')
Skip
(Browse
"invoicelines",
columns: (product, qty, price, total_price, invoice)
linkField: invoice,
name: "invoice_main"')
)
)
On_Test()
{
Alert (.Access.Vert.Horz.customer.Get())
}

}



I've tried some ways:

1) Alert (.Access.Vert.Horz.customer.Get())
2) Alert (.Access.Vert.Horz.Field("customer").Get())
3) use 'name' for field 'customer' like this:

Code:

Controller
{
Controls:
(Access
title: "Enter Invoices"
invoice
(Vert
(Horz invoice_number Skip (customer name: one) Skip invoice_main)
Skip
(Button "Test"')
Skip
(Browse
"invoicelines",
columns: (product, qty, price, total_price, invoice)
linkField: invoice,
name: "invoice_main"')
)
)
On_Test()
{
Alert (.Access.Vert.Horz.one.Get())
}

}



But neither works... I'm feeling that solution is simple and easy...

By the way: that does the first dot mean? It means that base object is omitted but what is the type of the obiect in this case — Controller?
 
 
#885
Re:How to adress controls 3 Years, 3 Months ago
Try this:

Just change you button to this, temporarily, and Inspect() will show you the addresses of everything.

On_Test()
{
Inspect(this)
}


Good Luck,

Todd
 
 
#886
Re:How to adress controls 3 Years, 3 Months ago
Thank you for idea, tscott. Inspect appears to be powerful and intersting tool. But I didn't see control names anyway... Even if I change code like this:

On_Test()
{
Inspect(.Access.Vert.Horz)
}

it gives me nothing... there are those names?
 
 
#888
Re:How to adress controls 3 Years, 3 Months ago
You should be able to find the controls via Inspect but it can be confusing.

Another way to reference controls is to use FindControl

control = .FindControl('mycontrol')

This depends on the controls having unique names. If you are including fields by name, then they will automatically be named (with the field name). If you are including controls not by field name, then you need to supply name: 'myname'.

FindControl searches the tree of controls so if you have a lot of controls it could be a little slow. We usually get references to the controls in New and save them in private instance variables:

.mycontrol = .FindControl('mycontrol')

Post edited by: andrew, at: 2007/05/07 17:29
 
 
andrew
 
#889
Re:How to adress controls 3 Years, 3 Months ago
Thank you very musch, Andrew. By the way, the FindControl method doesn't described in User's Manual. Actually, it doesn't mentioned at all... It would be good to describe it in future releases...
 
 
#892
Re:How to adress controls 3 Years, 3 Months ago
Sorry, some times things get added and we forget to document them. I have added Control.FindControl to the help.
 
 
andrew
 
#895
Re:How to adress controls 3 Years, 3 Months ago
I understand it clearly. As an active participant of some projects (such Wikikpedia) I know very well that to describe something usually not easier than to create it. Thank you for your work. I feel I'm falling in love with Suneido already :)
 
 
#898
Re:How to adress controls 3 Years, 3 Months ago
I do not mind helping. It would be great if you could record some of the things you are learning so other people might benefit. Probably the best method is to add stuff in the wiki and then I can take it from there to add to the documentation. Do not worry about the english, that can always be fixed later.

I am a big believer in the power of small, incremental improvements. Even a few short notes can be a good start. People who wait to "finish" some larger piece often never contribute anything.
 
 
andrew