[Gambas-user] Get the object of a component by name.

Tobias Boege taboege at ...626...
Wed Feb 24 18:09:27 CET 2016


On Wed, 24 Feb 2016, Matias De lellis wrote:
> Well...
> You're right .. The 'Instance' method seems to be hidden.. However, the example clearly indicates that this was the way to use it..??
> I have to research better, but if they have to be a static class, this does not help me ..
> 

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].

There is no method to obtain a general object from its name -- because
objects do not even need to have something like a "name". 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.

Regards,
Tobi

[0] http://gambaswiki.org/wiki/lang/createstatic

PS: And yeah, the completion window for "Class[...]" doesn't show here
    either.

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk




More information about the User mailing list