Trivia question: Name the base classes in VFP that may possess a Data Environment
FormSet, the lightest weight Data Environment container, reportedly with a maximum of 250 or so instances before GPF (is this still true in VFP 6? -- No, this is solved in VFP 6. See __ Form Set Instance Test)
Session, new in VFP6 SP3, and not particularly lightweight.
From Doug Hennigs Error Handling Paper:
"Interestingly, the DE is the one object that automatically calls its formís Error method if its own Error method has no code."
Data Environment classes are hugely useful! Most (if not all) commercial frameworks make extensive use of Data Environment classes. These classes are kept in
.PRG files since we cannot use the Visual Class Designer for data environments.
Visual FoxExpress' data environment classes (as well as their other data item classes) are not based on the VFP base classes and can therefore, be edited in the class designer.
I've noticed that Data Environment class hierarchies always tend to be very wide and shallow. -- Steven Black
Performance Tuning Tips In Microsoft Visual FoxPro by Erik Svenson, Category Performance
By using the Data Environment of the Form Designer or Report Designer, table open performance is much faster than executing USE, SET ORDER, and SET RELATION commands in the form's Load event. This is because Visual FoxPro uses low-level engine calls to open the tables and set up the indexes and relations.
Data Environment question:
We wrote a routine which will keep track of the response time for all SQL traffic in our app. It was easy enough to call this routine from our SQLEXEC and REQUERY wrappers. However, we also need this routine to run when a view is opened from the data environment. The DE does not provide any Before/After OpenEachCursor hooks. As an alternative, I can write a routine which, when called from the LOAD, steps through every cursor in the DE and opens the tables manually (if AutoOpenTables is .F.). Unfortunately, the DE also has no Cursors collection. The only way I've found to access a cursor from the DE is to know the name. Most of the time, we don't change the name from "Cursor1", etc, but that is a risky solution in framework-level code. Is there a better way to iterate through the cursors in a DE? Or am I going down the wrong path altogether? -- Zahid Ali
You could subclass the DE and create your own hooks. This is the approach the Codebook framework takes. All data-aware forms in codebook have a DE loader which creates an instance of the DE class specified in the cDataEnvironment property. When the DE class instantiates it in turn creates an instance of its cursor classes. Each one of these classes is added to a cursor array. Using this approach is would be simple to capture the time it takes to instantiate each cursor class. If you have the codebook framework handy look in the cdataenv.prg for the DE class code. - Michael GEmmons
Thanks for the idea - that solution seems a bit more bulletproof than the way I am going. However, I believe it would require more retrofitting. I solved my problem using AMEMBERS(,,2) to find the names of the objects contained in the Data Environment. -- Zahid Ali
See also Container Classes
Category Class Design Category Exam 70-155 Hot Topic
( Topic last updated: 2007.09.16 07:04:40 AM )