Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Jerzy Kopinski
  Where is Jerzy Kopinski?
 Pruszcz Gdanski
 Poland
 Jerzy Kopinski
 To: Terry Bottorff
  
 Chyenne
 
 Terry Bottorff
 Tags
Subject: RE: Data Environment
Thread ID: 47725 Message ID: 79934 # Views: 1 # Ratings: 0
Version: Visual FoxPro 6 Category: Forms
Date: Monday, October 24, 2005 7:25:36 AM         
   


> I would be very interested in seeing how you set relations using your method. Is there any actual code you post here? TIA.
>
>
> > > Can we add tables to the Form-Data Environment using Code instead of selecting it offline from Form Data Environment window ?
> > > If so, how ?
> > > And in which Form event the code should be entered ?
> > > Can we add tables to the Dataenvironment dynamically even after the form events like load, init and activate are over ?
> > > Once the tables are added to the Data Environment with code, will the tables be automatically closed when the form is released ?
> > >
> > > Thanks in advance.
> > > Tom
> > >

> >
> >
> > Hi Tom,
> >
> > You can define DataEnvironment of any form using OOP properties of VFP. In BeforeOpenTables method of DataEnvironment try to add all cursors and define its properties.
> >
> > this.AddObject("cursor1","cursor")
> > this.AddObject("cursor2","cursor")
> > ....
> > this.cursor1.alias='alias1'
> > this.cursor1.cursorsource='table1'
> > this.cursor1.database='C:\...\DTB1.DBC'
> > .....
> >
> >
> > Sometimes I redefine DE of forms in runtime, but usually to simplify the code I have to write, I add cursors defining DE of forms (it can be the same table) and then in the BeforeOpenTables method change only aliases, cursorsources and database.
> >
> > Jerzy Kopinski

>
>
>
> Buffie




Hi Terry,

One of my VFP application has to use DBF tables which are used by external application too. The external application is a business one which operates on independent databases, one set for a company.
Unfortunatelly, a table name of the same table can change, for example a table of customers for one company is cust01, for another cust02 etc. In my application I've built forms with DataEnvironment, which are partly define at run time.
At first, at design time I've defined DE with a few cursors (the same table). At run time in the BeforeOpenTable I change some properties of the cursors:

LOCAL li, lc

*- gAppID is a global with a company code
*- gPath is a global with a path to a database

this.cursor1.cursorsource='cust'+gAppId
this.cursor2.Alias='cust'
this.cursor2.cursorsource='invoice'+gAppId
this.cursor2.Alias='invoice'

WITH this
FOR m.li=1 TO 49
m.lc=".CURSOR"+ALLTRIM(STR(m.li,2))
IF TYPE(m.lc)='O'
&lc..Database=gPath+'\'+JUSTFNAME(&lc..Database)
ENDIF
ENDFOR
ENDWITH

In the Init method of DE I define relations:

LOCAL lcAlias
lcAlias=SELECT(0)
IF USED("CUST") AND USED("INVOICE")
SET ORDER TO custid IN cust
SELECT INVOICE
SET RELATION TO custid INTO cust
ENDIF
SELECT (lcAlias)

--------------------

The database hase to be opened before a form is used in the application.

IF there are some referentials integrity conditions defined in the databases, they are respected when you change data in tables.

Best regards,
Jerzy Kopinski

ENTIRE THREAD

Data Environment Posted by Tom Thomas @ 7/27/2004 11:00:59 AM
RE: Data Environment Posted by Boudewijn Lutgerink @ 7/27/2004 11:45:05 AM
RE: Data Environment Posted by Tom Thomas @ 7/27/2004 12:08:51 PM
RE: Data Environment Posted by Andy Kramek @ 7/27/2004 1:01:11 PM
RE: Data Environment Posted by Tom Thomas @ 7/27/2004 2:35:51 PM
RE: Data Environment Posted by Andy Kramek @ 7/27/2004 3:51:56 PM
RE: Data Environment Posted by Kent Jensen @ 10/20/2005 8:00:55 AM
RE: Data Environment Posted by Andy Kramek @ 10/20/2005 1:28:07 PM
RE: Data Environment Posted by Kent Jensen @ 11/2/2005 5:56:47 AM
RE: Data Environment Posted by Boudewijn Lutgerink @ 11/2/2005 7:18:44 AM
RE: Data Environment Posted by Victor @ 11/2/2005 4:22:03 PM
RE: Data Environment Posted by Ken Murphy @ 11/2/2005 6:03:11 PM
RE: Data Environment Posted by Kent Jensen @ 11/4/2005 4:00:02 AM
RE: Data Environment Posted by Boudewijn Lutgerink @ 11/4/2005 6:07:02 AM
RE: Data Environment Posted by Kent Jensen @ 11/4/2005 4:03:13 AM
RE: Data Environment Posted by Ken Murphy @ 10/20/2005 3:28:45 PM
RE: Data Environment Posted by Jerzy Kopinski @ 10/20/2005 9:14:50 AM
RE: Data Environment Posted by Terry Bottorff @ 10/21/2005 5:55:03 PM
RE: Data Environment Posted by Jerzy Kopinski @ 10/24/2005 7:25:36 AM