Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Unable to switch database used by a form
Message
From
24/10/2002 10:28:15
 
 
To
24/10/2002 04:56:06
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00714713
Message ID:
00714863
Views:
22
>How do we change database a form bound to at runtime?
>
Hi Cynthia,
I am using DE.BeforOpenTables event to
send entire DE as object, to public object that 'knows' where the real database is, and is capable of changing database property of DE cursors 'on fly'.
So in DE.BeforOpenTables method I am having one single line
for ALL my forms/reports.
oData.form_de(this)
In case I want to open database in code
I would use
local cDatabase
cDatabase=oData.get_database(TASTRADE.DBC)
open database (cDatabase)
set database to (cDatabase)
Here is simplified class that 'redirect' environment cursors
define class redirect_dataenvironment as custom
.
Network_path=''
.
.
    procedure get_database
        lparameters cDatabaseName
        local cDatabaseName
        return this.Network_path + cDatabaseName

    procedure form_de
        lparameters oDataEnvironment
        local i,j,db_name,arr_obj(1)
        amembers(arr_obj,oDataEnvironment,2)
        for i = 1 to alen(arr_obj)
            j = oDataEnvironment.&arr_obj(i) .baseclass
            if upper(alltrim(j)) = 'CURSOR'
                db_name=upper(justfname(allt(oDataEnvironment.&arr_obj(i) .database )))
                oDataEnvironment.&arr_obj(i) .database=this.get_database(allt(db_name))
                if !file(oDataEnvironment.&arr_obj(i) .database)
                    messagebox('['+oDataEnvironment.&arr_obj(i) .database+']'+chr(13)+;
                        'Not found Check your data')
                endif
            endif
        endfor

.
.
.

enddefine
So somewhere in init of yr appliacation you have to
instantiate public object based on this class
which will be able to 'know' where yr production database(s) are.
public oData
oData=createobject('redirect_dataenvironment')
oData.network_path='\\wherever it is '
I am using loader application to do that.
On every client machine there is ini file with path
towards server data. It could be UNC path or mapped drive.

Story can go even further by having path translation tables
stored on server that will let you use unlimited number of databases
in the same time (e.g. multiple companies)

It all depends how far you need to go.
Hope this will help you find your 'path'
*****************
Srdjan Djordjevic
Limassol, Cyprus

Free Reporting Framework for VFP9 ;
www.Report-Sculptor.Com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform