[Gambas-user] Get the object of a component by name.
Matias De lellis
mati86_dl at ...1877...
Wed Feb 24 20:04:12 CET 2016
Hi again,
>You seem to misunderstand Class["name"].Instance. In your first mail you>wrote:
>
>>> Dim hFirmata As Firmata
>>>
>>> hFirmata = Class["Firmata1"].Instance
>
>But Firmata1 is the name of one of your *objects*. The syntax Class["name"]
>searches for a *class* named "Firmata1", which likely does not exist in your
>component. You only mentioned the class Firmata.
>
>As I said earlier, Class["name"].Instance returns the unique automatic
>instance of an *auto-creatable* class, i.e. one with Create Static. It does
>not need to be fully static, just Create Static [0].
D'Oh!. You're right.
>There is no method to obtain a general object from its name -- because
>objects do not even need to have something like a "name".
Ok. It's a shame
If so, and considering the next point, I can not do as I want.
>It is a different>matter, though, if Firmata is a graphical control. Graphical controls always
>have a name property and you can use a Form's Controls property to search a
>control by name like this:
>
> hMyFirmata = FMain.Controls["Firmata1"]
>
>Note again: this only works if you know the form (FMain in this case) where
>you want to search your object and the object is a control.
I thought it, but as inherited from SerialPort (Not UserControl) does not work..
I implemented this in the previous attached example, and prints all controls except virtuals.
> Dim hControl As Control
> Dim hForm As Form Then
> If Me.Parent Is Form ' Always can iterate to find the Form..
> hForm = Me.Parent
> For Each hControl In hForm.Controls
> Debug hControl.name
> Next
> Endif
May need to do inherit from UserControl but I have to add even more code to relate the UserControl parent with the child SerialPort properties and events..
Regards,
Thank for all,
More information about the User
mailing list