[Gambas-user] Constant order to process in component creation

Tobias Boege taboege at ...626...
Thu Oct 2 23:18:25 CEST 2014


On Thu, 02 Oct 2014, Jorge Carri??n wrote:
> Excuse my poor English. What I mean with "processing properties" is the
> execution of triggered methods _read and _write of the propertie.
> What I mean is  somenthing like that:
> 
> Export
> 
> Inherits TableView
> 
> Public Const _Properties As String = "*,conexion,sqlstring"
> 
> Property conexion As Connection
> Property sqlstring As String
> 
> Private $conexion As Connection
> Private $sqlstring As String
> 
> Public Sub fill_the_grid()
> 
>   $conexion.Exec($sqlstring)
>   ...
>   etc.
>   ....
> 
> End
> 
> Public Function conexion_read() As Connection
> 
>   Return $conexion
> 
> End
> Public Sub conexion_Write(Value As Connection)
> 
>   $conexion = Value
> 
> End
> 
> Public Function sqlstring_read() As String
> 
>    Return $sqlstring
> 
> End
> Public Sub sqlstring_write(value As String)
> 
>    $sqlstring = value
>    fill_the_grid()
> 
> End
> 
> 
> Both properties, conexion and sqlstring, are filled with its values in the
> IDE in design time.
> When run the program, somtimes the sqlstring_write sub is launched before
> conexion_write() sub. And then, obviously there are a error in
> $conexion.Exec($sqlstring) line...
> Some times If I change the size of the form or if I add som controls more
> to the form, it works fine.
> 
> There is a way to force the conexion property to be filled before de
> sqlstring property?
> 
> Hope this time I've been more clear.
> 

Yes, it was. (Let me make a quick note on vocabulary here before I proceed:
you said you programmed a "component" but "component" in the narrower sense
around Gambas means a sort of shared library (the gb.* things you link to
your project, like gb.qt4). Your class above _may_ be part of a component
but you are actually talking about what we normally call a "control", i.e.
a class which can be put on a graphical form. I know people who call both
things "component" but this often leads to confusion. And your question
revolves around that single class, and whether it's part of a component is
irrelevant here. Remember the 4 C's: classes, controls, components and
confusion :-))

About your question: If I was you, I wouldn't want to rely on a specific
order of execution. What if the user sets conexion = Null *mid-execution*?
You need to handle the case $conexion = Null in your fill_the_grid():

Public Sub fill_the_grid()
  If Not $conexion Or If Not $conexion.Opened Then Return ' Do nothing
  $conexion.Exec($sqlstring)
  ' etc.
End

Similarly, maybe $sqlstring should get a sensible default value since IIRC
an empty Exec() also throws an error.

Does this help you?

Regards,
Tobi

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




More information about the User mailing list