Hi Andrus,
Before you can the CursorSource property, you have to CloseTables(). If you are doing this in a Form, it should be done in the Form's Load Event. You may want to create an abstract method in you base Form class called something like
LoadCursors and then call it from the Form's Load Event.
LoadCursors:
/ LOCAL i, aCursors[1]
/
/ AMEMBERS(aCursors, oForm.DataEnvironment, 2)
/
/ WITH oForm.DataEnvironment
/
/ .CloseTables()
/
/ FOR i = 1 to ALEN(aCursors)
/ WITH EVAL("." + aCursors[i])
/ IF .BaseClass = "Cursor"
/ .CursorSouce = "foo"
/ .DataBase = "d:\allfoopath\allfoo.dbc"
/ ENDIF
/ ENDWITH
/ ENDFOR
/
/ IF .AutoOpenTables
/ .OpenTables()
/ ENDIF
/
/ENDWITH
Keep in mind that if the Cursor is in a DataBase, do not include the .dbf extention for the cursor - only include the fullpath for free tables.
The BeforeOpenTables Event actually fires
during OpenTables() and is kinda tricky to do anything with.
You can get real creative with this stuff.
>I have forms with tables in their Dataenvironment.
>At form design time, VFP stores relative path of those cursors into cursor CursorSource. property
>
>I need to change CursorSource property because at run-time, files are at different locations.
>The only reasonable place to do it seems to be BeforeOpentables event.
>However, it is not possible to loop through cursors: dataenvironment does not have objects collection and cursor object names are changed.
>
>Is there a way to do this?
>
>Currently I use the followin code in BeforeOpenTables.
>But cursor names are changed sometimes, so this will not work:
>
>i = 1
>do while type('this.Cursor'+ltri(str(m.i))+'.name' ) = 'C'
> local lobj
> lobj = eval( 'this.Cursor'+ltri(str(m.i)) )
> if type( 'o.CursorSource')='C'
> o.CursorSource = 'c:\mypath'
> endif
> i = i + 1
> enddo
- Jeff