2. Agenda
Collections in VFP
Working with Collections
Writing Better Code with Collections
Using Collections for Object Manipulation
Adding Power to VFP Arrays
Collections vs. Arrays
Merging Arrays & Collections
3. Who Am I
President F1 Technologies since 1990
Co-author Visual FoxExpress
Consultant
Xbase Developer since dBase III/FoxBase
1987
7. The Collection Class
New in VFP 8
Key Properties
Count
KeySort (0-3)
Key Methods
Add(eItem, cKey, eBefore, eAfter)
Item(eIndex)
GetKey(eIndex)
8. Iterating Collections
FOR lnI = 1 TO loCollection.Count
FOR EACH loObject in loCollection
FOR EACH loObject in loCollection
FOXOBJECT
Examples: Iterate1.prg, Iterate2.prg,
Iterate3.prg
9. UI Support for Collections
Listbox
ComboBox
Example: CollectionDemo.SCX
10. Writing Better Code with
Collections
Problem: This.Parent.Page2.txtCompany
creates a tightly coupled dependency.
Solution: Dynamically retrieved Object
references eliminate tight coupling.
o=o(…) or o=f(…)
12. Returning an Array
From within a class method a member
array can be used as the return value.
A function can return an array by calling a
class method that returns an array.
Example: aConcact in utility.prg
14. Wrapping an Array in a Collection
Fox Data Objects – ADO / LINQ like
DataCollection.prg, cDataCollection of
cData
15. Conclusion
Collections in VFP provide convenient ways to
access objects
Retrieving object references from collections can
make code a lot more flexible and stable
VFP has a lot of powerful options available on
arrays
Collection and array implementations are just
different enough that each has their own place.