[Gambas-user] Access a property via string (Introspection like)
Benoît Minisini
gambas at ...1...
Wed Jun 24 18:51:17 CEST 2009
> Hello,
>
> I want to set a property value using strings for, accesing a form, then
> a grid, then a cell inside the grid, the text property and finally set
> the value for it.
>
> Here a wannabe code that obviously is failing to do the idea:
>
>
> PUBLIC SUB setMatrix(path AS String, dims AS Integer[], prop AS String,
> Valor AS String)
>
> ' Divido a path por los puntos
>
> DIM s AS String[]
> DIM cad AS String
> DIM c AS Control
> DIM g AS GridView
> DIM f AS Form
> DIM o AS Object
> DIM i AS Integer
>
>
> s = Split(path, ".")
>
>
> IF s.Count = 0 THEN
> Message("Revisar argumentos")
> END IF
>
> FOR i = 0 TO Windows.Count - 1
> IF (Lower(s[0]) = Lower(Windows[i].Name)) THEN
> f = Windows[i]
> EXIT
> END IF
> NEXT
>
> IF NOT IsNull(f) THEN
>
> g = f[s[1]]
>
>
> g.row = dims[0]
> g.column = dims[1]
>
>
>
> Object.SetProperty(g.Current, prop, Valor)
> END IF
>
>
>
> END
>
> As you can imagine, Gambas stops on the "Object.SetProperty" line,
> complaining about that it cannot use the "virtual" class that g.Current
> belongs to.
>
> I need this because the idea is to access in runtime to any
> object/property/method from outside gambas (for example, a Python
> script).
>
> Any help would be greatly appreciated.
In the development version, you have an Assign() function that evaluates an
assignment expression. It allows you to do what you want.
--
Benoît
More information about the User
mailing list