Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How can I change dbc path in form
Message
De
11/10/2006 05:31:42
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Divers
Thread ID:
01160849
Message ID:
01161125
Vues:
38
This message has been marked as the solution to the initial question of the thread.
>>I have the following procedures:
>>
>>
>>************************************************************************************************
>>*
>>*  Routine for setting the database directory location for the form
>>*
>>FUNCTION SetDBCPath
>>LPARAMETERS poFormDE,pcDBCPath,pcDBCName
>>LOCAL lcDBCName, lcFilePath, lnNumCursors, lnNdx
>>lcDBCName  = FORCEEXT(pcDBCName,"DBC")
>>lcFilePath = ADDBS(pcDBCPath) + lcDBCName
>>lnNumCursors = AMEMBERS(lcProperties,poFormDE,2)
>>FOR lnNdx=1 TO lnNumCursors
>>	IF UPPER(LEFT(lcProperties[lnNdx],6)) = "CURSOR"
>>		IF ATC(lcDBCName,poFormDE.&lcProperties[lnNdx]..database) > 0
>>			poFormDE.&lcProperties[lnNdx]..database = lcFilePath
>>		ENDIF
>>	ENDIF
>>ENDFOR
>>ENDFUNC
>>
>>
>>This is called in the Dataenvironment.BeforeTablesOpen() event:
>>
>>
>>SetDBCPath(this,gcDBCPath,"Data")
>>
>>
>>Where "Data" is the name of the database, and gcDBCPath is the location of the database at runtime. The variable gcDBCPath is global (or can be a custom property added to _SCREEN) and determined at the start of the program. This will change the location of the tables within the database for the dataenvironment.
>>
>>For free tables, use the following:
>>
>>
>>************************************************************************************************
>>*
>>*  Routine for setting the free table directory location for the form
>>*
>>FUNCTION SetDBFPath
>>LPARAMETERS poFormDE,pcDBFPath
>>LOCAL lnNumCursors, lnNdx, lcDBFName
>>LOCAL ARRAY lcProperties[1]
>>lnNumCursors = AMEMBERS(lcProperties,poFormDE,2)
>>FOR lnNdx=1 TO lnNumCursors
>>	IF UPPER(LEFT(lcProperties[lnNdx],6)) = "CURSOR"
>>		IF EMPTY(poFormDE.&lcProperties[lnNdx]..database)
>>			lcDBFName = JUSTFNAME(poFormDE.&lcProperties[lnNdx]..CursorSource)
>>			poFormDE.&lcProperties[lnNdx]..CursorSource = pcDBFPath + lcDBFName
>>		ENDIF
>>	ENDIF
>>ENDFOR
>>RETURN
>>ENDFUNC
>>
>This is neat, however...
>How does one set the data environment for a lot of forms? I have a base class that I use fordata entry. There is no DE in a form class, so where do I add the call to the SetDBFPath function...
>
>I don't want to open a whole lot of forms and add the same line to call the function...
>
>Mike

Mike,
Re: How can I change dbc path in from Thread #1160849 Message #1160893
It handles the case for forms that have DE and those that do not. To expand that further, in actual development I have 'myApp' class in main.prg. I have 2 prgs just for development (s() and c() - start and close). What s() does is to create oApp from main with the given paths.
*s.prg
Close Databases All
Clear All
Public oApp
oApp = Newobject('myApp','main.prg')

*c.prg
CLOSE DATABASES all
CLEAR ALL
Clear prog
Just creation of oApp is sufficient because it reads "working" DBC and Data folder from a local file (and restores to default development DBC,path upon destroy due to c() call when I'm done).
When I'm using customer data or some test data, I simply change dbc name and path in that external file, s() and test my individual form,prg etc or app itself. The development data folder is left intact.
PS: IMHO in a VFP application there is only one public variable and that is oApp. Rest should be local with some rare private exceptions maybe.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform