On 01/10/2015 01:37 PM, Tobias Boege wrote:
> On Sat, 10 Jan 2015, T Lee Davidson wrote:
>> On 01/10/2015 11:08 AM, J?rn Erik M?rne wrote:
>>>
>>>> Hello,
>>>>
>>>>
>>>>
>>>> One can address a control on another form with fMain.txtHello.Text. This
>>>> syntax also works for other container objects. I have a form with a panel
>>>> control. There are several controls within the panel. To avoid naming
>>>> conflicts I want to keep the panel controls separate from the parent form.
>>>> Something like panel.txtEdit.Text would be great but, it does not work. I
>>>> can get the "children" collection of the panel and get the control names.
>>>> That does not help. I need to get to the control and use its properties and
>>>> events. Is there a way to do this?
>>>>
>>>>
>>>>
>>>> Thanks
>>>>
>>> This is the way: Panel1.Children[1].Text
>>>
>>
>> The documentation for Container.Children says that it, "Returns a collection 
>> [...]" But it does not return a Collection (class).
>>
>> That's too bad. The ability to do Panel1.Children["TextBox1"].Text would be 
>> nice.
>>
>
> If Panel1's containing Form is FForm, then you can do
>
>    FForm.Controls["TextBox1"]
>
> to have this access pattern. Since for every non-Form control, there must be
> a Form somewhere up in the parent chain, it is always an option to go up
> Panel.Parent, Panel.Parent.Parent, etc. to find the *first* container which
> is a Form and then use its Controls property as shown above.
>
> Since all controls (recursively[*]) included in a form must have different
> names, there are no name clashes by design.
>
> [*] It is not so easy if your Form embeds other Forms. If you want to, say,
>      list all control names in your form, you descend recursively from the
>      Form through all containers and Print their children's names.
>
>      In this process, you may not descend into containers which happen to be
>      Forms because another Form is a brand new namespace and you don't want
>      the new names which are in there.
>
> To test whether a container is a form, you can use the Is operator[0].
>
> Regards,
> Tobi
>
> [0] http://gambaswiki.org/wiki/lang/is
>

Thanks for the elucidation, Tobi. But, I must be missing something.

FForm.Controls["TextBox1"] returns a Control which does not have a Text 
property.

.Parent ("Panel1.Parent") returns a Container which also does not have a Text 
property.

If we do something like

        Dim hForm As Form
        If Panel1.Parent Is Form Then hForm = Panel1.Parent

we would have hForm.Controls["TextBox1"], which returns a Control with no Text 
property.


So, we seem to be right back to needing to know the integer index of the 
control in the container:
Jørn Erik Mørne wrote, "This is the way: Panel1.Children[1].Text"


I did not realize that my little comment would elicit a response, and I do not 
wish to hijack Martin's thread.
So, unless there is a better way to access the properties of a Container's 
children, then it seems his question has been answered.


Lee
__________

"Artificial Intelligence is no match for natural stupidity."

------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to