[Gambas-user] Get the object of a component by name.
Matias De lellis
mati86_dl at ...1877...
Fri Feb 26 22:02:37 CET 2016
Hi Tobi,
Sorry about the delay.
> OK, then another, more self-contained way. You have a class Firmata which is
> instantiable and you want to keep track of the instances, right? Then modify
> Firmata.class like so:
>
> Static Private $cObjects As New Collection
>
> Static Public Sub _get(Name As String) As Firmata
> ' Search through registered objects
> Return $cObjects[Name]
> End
>
> Public Sub _new(Name As String)
> ' Register every newly created Firmata object
> $cObjects[Name] = Me
> End
>
> There is a static Collection which records every newly created object. You
> must now specify a name for each Firmata object on creation. Given a string
> variable sName which contains a the name of an existing Firmata object you
> can obtain the object simply as
>
> hMyFirmata = Firmata[sName]
>
> The above code will give you circular reference errors and it does not
> include a way to remove an instance from the Collection so that its refcount
> drops to zero and the Firmata object can be deleted. I have not enough time
> ATM to make a better example, but if you get the idea, I'm sure you can fix
> the remaining issues.
It seems an interesting option, but still did not dedicated enough time to even analyze.
I have little free time these days.. :(
Next week I will try continue this. ;)
Regards and thanks for all,
Matias
More information about the User
mailing list