Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Unable to switch database used by a form
Message
 
 
To
24/10/2002 04:56:06
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00714713
Message ID:
00714782
Views:
20
I do not even mess with that. In the BeforeOpenTables of the DE, I have the following code:

SET TALK OFF
SET DELETED ON
SET EXCLUSIVE OFF
SET MULTILOCKS ON
SET DATABASE TO DATABASE_NAME

The DATABASE_NAME above is a constant that is defined in my DEFAULTS.H header file:

#DEFINE DATABASE_NAME "MyDBC"

All my forms have DEFAULTS.H as the default constants file.

I then run the following code which strips the path to the database that is stored in the properties of each cursor in the DE:
set talk off
set deleted on
local lnRetVal, i, j, lcFile, llFound, lcStr, lcPath
local array laFiles(1,2)
cd .\forms   && location where I keep all forms for this project
lnRetVal = adir(laFiles, "*.scx")
for i = 1 to lnRetVal
   lcFile = laFiles(i,1)
   use (lcFile) excl
   locate for "DATABASE" $upper(Properties)
   do while !eof()
      llFound = .f.
      for j = 1 to memlines(properties)
         if alltrim(upper(substr(mline(properties, j), 1, 8))) = "DATABASE"
            llFound = .t.
            exit
         endif
      next
      if llFound
         lcStr = mline(properties, j)
         lcStr = alltrim(substr(lcStr, 11))
         lcPath = justpath(lcStr)
         lcPath = addbs(lcPath)
         replace next 1 properties with strtran(properties, lcPath, "")
      endif
      continue
   enddo
   pack
   use
   compile form (lcFile)
next
cd..
>How do we change database a form bound to at runtime?
>
>I tried the following with tsBaseForm class (Tastrade sample app):
>
>Load event:
>x=this.dataenvironment.objects[1].database
>this.dataenvironment.objects[1].database= strtran(x,'C:\','D:\')
>
>Then I created MyForm based on tsBaseForm. I put Customer table in its dataenvironment and set DE's AutoOpenTables to .F.
>I also dragged Customer table from DE to form so it created a grid with RecordSource property set to Customer.
>
>When I run MyForm (from inside Tastrade app, of course) it went fine but when I back to form designer and change grid.column.ControlSource to customer.Name (previously empty) and run the form again an error appeared:
>
>Data environment is already UNloaded.
>Method: myform.dataenvironment.CloseTables
>Line: 0
>
>When I chose Ignore, another error came up but with blank message. When I click Ignore I threwn back to menu (the form never run)
>
>It seems that problem occured if I change grid.column.ControlSource to something other than "(None)" (default).
>
>What I'm looking for is a workaround other than open tables manually in form.Load
>
>Thank you in advance
Mark McCasland
Midlothian, TX USA
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform