Can Eval do auto Context ?

Post

Posted
Rating:
#1 (In Topic #1484)
Regular
sergioabreu is in the usergroup ‘Regular’
Hello
 
  In Eval we have to pass a collection always with all variables needed to unknow symbols ??

  1) Does Eval get all Sub  or Function local vars automatically ? (Declared variables and parameters)
  2) Is there a way to do it ?
 
  I tried to run an Eval inside  a Sub refering to a local variable and it didn't get the local variable. Throwed a Unknown Symbol error.

  Eval is used mostly to facilitate this concatenation with "local" or "scope" variables…
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’
 Eval only sees global Public variables.

Variables local to a Sub / Function (with Dim) are private to that function so must be added to the context collection.
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
For Public variables local to the same class you must use the class name.

eg.
In a class called FMain.class

Code (gambas)

  1.  
  2.  
  3. Public Sub Form_Open()
  4.  
  5.   iNum = 2  ' no need to use FMain.iNum here
  6.  
  7.   Print Eval("Screens.Count * FMain.iNum")  ' This will work okay
  8.  
  9.   ' Print Eval("Screens.Count * iNum")  ' This will error, unknown symbol
  10.  
  11.  
  12.  

For Private variables you will also need to use the context Collection
Online now: No Back to the top
1 guest and 0 members have just viewed this.