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

Tobias Boege taboege at ...626...
Wed Feb 24 00:09:44 CET 2016


On Tue, 23 Feb 2016, Matias De lellis wrote:
> Dear All,
> 
> 
> I'm starting a new project. In a few words is a set of controls to interact with Arduino using the Firmata protocol[1]. 
> To understand better, in general the idea is inspired by Ctrlr[2] that allows 
> interact with MIDI controllers adding simple components in a form..
> 
> 
> I started implementing it like that
>  * A global "Firmata" component with:
> 
>    - A virtual "Firmata" control that Inherits SerialPort that is responsible for the communication through the serial port. It is completely configured graphically, and provides new functions (To send commands to Arduino) and events (To notify arduino event to others Controls) to interact with Arduino.
> 
>    - Others controls Inherits UserControls. Eg: A FirmataSwitchButton to show the status of a digital input, or FirmataProgressBar to show a Analog Input.. Always responding to events of Firmata Control
> 
> 
> My idea is that it should be completely graphic, and the procedure would be like this:
> 
>  1. Add a Firmata control.
>  2. Configure the control: ??NAME!(Eg: "Firmata1"), port, baud, etc..
>  3. Add FirmataSwitchButton.
>  4. Configure the FirmataSwitchButton: Digital Pin to represent, but fundamentally the Firmata control used represented by the string property as "Firmata1"..
> 
> 
> Now, through the name I need to get the object Firmata configured to make controls interact with it.
> Why not make the controls inherit from Firmata? Because it would configure all controls individually.. The idea is to set up once, to use many.. ;)
> 
> Anyone know how to do this?
> I found this[3], but it seems not work
> 
> > Dim hFirmata As Firmata
> 
> > hFirmata = Class["Firmata1"].Instance
> 
> 
> When running Gambas respond: "Is not a object".
> 

I'm not sure if I understand you correctly. [ In case I don't, I would
suggest that you maybe use pseudo code and simpler (Gambas-only) terms to
state what you want to do. I mean: should I be required to look up the
"Firmata protocol" and "Ctrlr" and "MIDI" to answer your question about a
Gambas programming technique? --- Ideally, no. ]

So, what I read out of your mail is that you have one object Firmata1 which
has a certain configuration. You now want to add controls dynamically to the
Form which should inherit Firmata1's configuration by obtaining a reference
to the Firmata1 object.

If this understanding is correct, you have several possibilities, three of
which are:

  1. Why must Firmata be an instantiable class? Wouldn't a module suffice
     here? (A module is a special kind of class which only has one instance.
     If you only have one serial port to communicate with in your
     application, a module should be fine.) Modules are like global
     variables so it will be easy for your controls to obtain a reference
     to this object.

  2. Can't you pass the Firmata1 object to the constructors of the controls?

  3. (A refinement of 2.) Make the Firmata class a Container object and
     create the controls inside the container Firmata1. This way, the
     controls can access their parent Firmata1 and its configuration
     directly. This is how the DataSource control from gb.db.form works,
     if you are familiar with that.

Regards,
Tobi

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




More information about the User mailing list