Feltman collections

15
Collections, Arrays & Collections, Arrays & Iteration Iteration Mike Feltman Mike Feltman F1 Technologies F1 Technologies

description

 

Transcript of Feltman collections

Page 1: Feltman collections

Collections, Arrays & Collections, Arrays & IterationIteration

Mike FeltmanMike Feltman

F1 TechnologiesF1 Technologies

Page 2: Feltman collections

AgendaAgenda Collections in VFPCollections in VFP Working with CollectionsWorking with Collections Writing Better Code with CollectionsWriting Better Code with Collections Using Collections for Object ManipulationUsing Collections for Object Manipulation Adding Power to VFP ArraysAdding Power to VFP Arrays Collections vs. ArraysCollections vs. Arrays Merging Arrays & CollectionsMerging Arrays & Collections

Page 3: Feltman collections

Who Am IWho Am I

President F1 Technologies since 1990President F1 Technologies since 1990 Co-author Visual FoxExpressCo-author Visual FoxExpress ConsultantConsultant Xbase Developer since dBase Xbase Developer since dBase

III/FoxBase 1987III/FoxBase 1987

Page 4: Feltman collections

““Objects” Collections in VFPObjects” Collections in VFP

_SCREEN, _VFP, FormSet, _SCREEN, _VFP, FormSet, DataEnvironment, Toolbar, DataEnvironment, Toolbar, Container, PageFrame, Page, Grid, Container, PageFrame, Page, Grid, Column, CommandGroup, Column, CommandGroup, OptionGroup, Container, Custom, OptionGroup, Container, Custom, ControlControl

Page 5: Feltman collections

Other Collections in VFPOther Collections in VFP _VFP_VFP

FormsForms ProjectsProjects

ProjectProject FilesFiles ServersServers

XMLAdapterXMLAdapter TablesTables

XMLTableXMLTable FieldsFields

Page 6: Feltman collections

““Pseudo” Collections in VFPPseudo” Collections in VFP _SCREEN.Controls_SCREEN.Controls Form.ControlsForm.Controls Custom.ControlsCustom.Controls Control.ControlsControl.Controls Toolbar.ControlsToolbar.Controls Container.ControlsContainer.Controls Column.ControlsColumn.Controls

_SCREEN.Forms_SCREEN.Forms FormSet.FormsFormSet.Forms CommandGroup.ButtCommandGroup.Butt

onsons OptionGroup.ButtonsOptionGroup.Buttons PageFrame.PagesPageFrame.Pages Grid.ColumnsGrid.Columns

Page 7: Feltman collections

The Collection ClassThe Collection Class New in VFP 8New in VFP 8 Key PropertiesKey Properties

CountCount KeySort (0-3)KeySort (0-3)

Key MethodsKey Methods Add(eItem, cKey, eBefore, eAfter)Add(eItem, cKey, eBefore, eAfter) Item(eIndex)Item(eIndex) GetKey(eIndex)GetKey(eIndex)

Page 8: Feltman collections

Iterating CollectionsIterating Collections FOR lnI = 1 TO loCollection.CountFOR lnI = 1 TO loCollection.Count FOR EACH loObject in loCollectionFOR EACH loObject in loCollection FOR EACH loObject in loCollection FOR EACH loObject in loCollection

FOXOBJECTFOXOBJECT

Examples: Iterate1.prg, Iterate2.prg, Examples: Iterate1.prg, Iterate2.prg, Iterate3.prgIterate3.prg

Page 9: Feltman collections

UI Support for CollectionsUI Support for Collections

ListboxListbox ComboBoxComboBox

Example: CollectionDemo.SCXExample: CollectionDemo.SCX

Page 10: Feltman collections

Writing Better Code with Writing Better Code with CollectionsCollections

Problem: This.Parent.Page2.txtCompany Problem: This.Parent.Page2.txtCompany creates a tightly coupled dependency.creates a tightly coupled dependency.

Solution: Dynamically retrieved Object Solution: Dynamically retrieved Object references eliminate tight coupling.references eliminate tight coupling.

o=o(…) or o=f(…)o=o(…) or o=f(…)

Page 11: Feltman collections

Using Collections for Multiple Using Collections for Multiple Object ManipulationsObject Manipulations

ACAC CCCC WCWC

Page 12: Feltman collections

Returning an ArrayReturning an Array From within a class method a member From within a class method a member

array can be used as the return value.array can be used as the return value. A function can return an array by calling A function can return an array by calling

a class method that returns an array.a class method that returns an array.

Example: aConcact in utility.prgExample: aConcact in utility.prg

Page 13: Feltman collections

Array UtilitiesArray Utilities aCompactaCompact aConcataConcat aFirstaFirst aJoinaJoin aLastaLast aReverseaReverse aUniqueaUnique aWithoutaWithout ArrayDemo.PrgArrayDemo.Prg

Page 14: Feltman collections

Wrapping an Array in a Wrapping an Array in a CollectionCollection

Fox Data Objects – ADO / LINQ likeFox Data Objects – ADO / LINQ like DataCollection.prg, cDataCollection DataCollection.prg, cDataCollection

of cDataof cData

Page 15: Feltman collections

ConclusionConclusion Collections in VFP provide convenient ways Collections in VFP provide convenient ways

to access objectsto access objects Retrieving object references from collections Retrieving object references from collections

can make code a lot more flexible and stablecan make code a lot more flexible and stable VFP has a lot of powerful options available VFP has a lot of powerful options available

on arrayson arrays Collection and array implementations are Collection and array implementations are

just different enough that each has their own just different enough that each has their own place. place.