Vous êtes sur la page 1sur 16

PRE201: Introduction to Visual FoxPro

This Workshop introduces you to Visual FoxPro and the basics o ho! to use it" Plan to attend this session i you#re a be$innin$ Visual FoxPro de%eloper or you ha%en#t !orked in Visual FoxPro be ore& and you !ould like to $et 'ore out o the (e%)on that ollo!s"

In the be$innin$& !as the dot


What is Visual FoxPro?

Its a standalone tool for data manipulation Its a development tool for standalone, LAN, client-server, applications Its a data#ase en$ine Its a pro$rammin$ lan$ua$e Its part of Visual %tudio Its an inte$ral part of "icrosoft Windo&s Its a reli$ion !" and We#

Well, 'es and no( )he first four are pro#a#l' true( )he last three are pro#a#l' not, althou$h 'ou ma' find adherents &ho #elieve some, all, or none, of those statements( )he' also sa' theres one #orn ever' minute( Lets di$ a little, startin$ &ith a little histor' lesson( Wa'ne *atliff &as the pro$rammer, &or+in$ for "artin "arietta and su#contractin$ for the ,et Propulsion La#orator', &ho started to create a natural-lan$ua$e-st'le data#ase en$ine and manipulation lan$ua$e on his I"%AI -.-. computer, in assem#ler, in his spare time, in order to improve his chances in the foot#all pool( !ne thin$ lead to another, and he &as soon mar+etin$ the product as d/A%0( It &as purchased #' Ashton-)ate, then /orland, and is no& o&ned #' d/A%0, Inc( It &as one the +e' products in the ma+in$ of the 1P *evolution2 of the 34-.s that lead to a P on ever' des+( In its he'da', a num#er of lan$ua$e-compati#le 1clones2 such as Fox/ase, lipper, d#"AN and man' others competed fiercel' for the hearts and minds and &allets of developers( Fox %oft&are, #ased in Perr's#ur$, !hio, &as formed and run #' 5r( 5avid Fulton( 615r( 5ave2 as he &as affectionatel' +no&n, &as a $reat sho&man, &ho deli$hted in meetin$ and presentin$ to his customers( 7e is a ma8or reason that 5ev on continues to this da'(9 Fox %oft&are created a fast, interpreted version of the d/A%0 runtime and then #ro+e the mold in $oin$ #e'ond the standard to introduce man' additional features( Fox/ase ran on "ac, 5!% and :nix platforms( FoxPro, startin$ &ith version ;(<, supported Windo&s as &ell( Fox %oft&are &as ac=uired #' "icrosoft in "arch of 344;( While there &as a "acintosh version of Visual FoxPro >(., su#se=uent versions run onl' on the Windo&s platforms( In this paper, I loo+ at ho& to learn Visual FoxPro( "asterin$ a computer lan$ua$e is similar to masterin$ another s+ill( ?ou need to pro$ress throu$h the levels of novice,

apprentice, and 8ourne'man to reach the master level( Achievin$ master' is not a su#8ect that can #e tau$ht in a mornin$, nor covered in a short paper( /ut master' starts &ith a $ood understandin$ of the fundamentals, and that is &hat I tr' to cover here( First, I loo+ at data, as is it the data that is reall' &hat it is all a#out @ the application is 8ust a &a' to #etter mana$e the data( %econd, I loo+ at the lan$ua$e itself, ho& to interact &ith the data, read it in and displa' it( )he third section $oes #e'ond the #asic procedural parts of the lan$ua$e into the po&er tools, control and o#8ects that #uild applications( Finall', the fourth section tries to pull to$ether all of the previous sections, and provide a perspective and philosoph' of ho& an entire application should #e put to$ether(

Part I * It+s the (ata


/efore &e can plun$e headfirst into developin$ FoxPro applications, a $lossar' and a #it of a#stract theor' &ill ma+e the applications &or+ much #etter(

Terminology
A field is a sin$le piece of information, such a persons first name or an items price( 5ivide up 'our information so that fields can stand on their o&n, and dont need to #e su#-divided &hen 'ou are processin$( For example, if 'our part num#er is composed of a part t'pe, a re$ion code, a ratin$ and a su#-part num#er, such as AN->>AB-3;>B, it can often #e #etter to #rea+ that information into separate fields and com#ine it &hen needed, rather than tr' to #e constantl' splittin$ the field &hen loo+in$ for all parts from one re$ion( 0ach field has a sin$le datatype( 5ata t'pes hold a particular +ind of informationC have upper and lo&er limits on their capacit'C and are restricted on &hat information the' can hold( Fields ma' #e character, inte$er, date, datetime 6a com#ination of date and time9, numeric, dou#le, float, currenc' lo$ical 6true or false9, memo 6ver' lon$ freeform text or #inar' data9( %pecialiDed datat'pes exist to hold !L0 information 6$eneral fields9, "acintosh #inar' 6picture fields9, #ut are rarel' used( A collection of fields &hich hold a sin$le piece of information are $athered to$ether to form a record( For example, 'ou mi$ht record a chec+ received from a customer asE Field name ustomer Num#er hec+ Num#er Amount 5ate *eceived Type Inte$er Inte$er Numeric 64,;9 5ate Data B>;3 <FGH43.(33 ;; ,ul' ;..3

A collection of these records &ould form a table( )he ta#le of data can #e vie&ed in man' &a's, #ut the standard form used #' the Fox /*!W%0 command loo+s li+e thisE ustom er hec + Amou nt 5ate

3;B> >;>; ;>;>;

>3;3 B>;B > B;

;>; >>B> B>(>B

.3I.3I34 .3 .;I.;I;. .; .>I.>I34 .>

)his $eometr' leads to other names for the items, records are often called rows and fields columns. In FoxPro, there are usuall' three &a's to do an'thin$, or no &a' at all( )o create this ta#le &e mi$ht t'peE CREATE And let the user interface $uide us to &hat &e &anted to create( !r &e could t'peE CREATE TABLE CheckRec (Customer I, Check I, Amount N(9,2), Date D) !rE DIMENSION a!"e #$%,&' #"mens"on a!"e #$%,&' a!"e #$(,(' ) *Customer* a!"e #$(,2' ) *I* a!"e #$(,+' ) % a!"e #$(,%' ) , a!"e #$(,&' ) -!a!"e #$2,(' ) *CheckNo* a!"e #$2,2' ) *I* a!"e #$2,+' ) % a!"e #$2,%' ) , a!"e #$2,&' ) -!a!"e #$+,(' ) *Amount* a!"e #$+,2' ) *N* a!"e #$+,+' ) 9 a!"e #$+,%' ) 2 a!"e #$+,&' ) -!a!"e #$%,(' ) *ChkDate* a!"e #$%,2' ) *D* a!"e #$%,+' ) . a!"e #$%,%' ) , a!"e #$%,&' ) -!CREATE TABLE CheckRec !ROM ARRA/

a!"e #

0ach of these &a's of creatin$ a ta#le has advanta$es and disadvanta$es( )he first is easiest for a #e$innerC he or she is $uided in the choices to #e made( )he second is =uic+erC one line of t'pin$ and 'oure done( )he third form, thou$h, leads to the most flexi#ilit' and control(

Design and Normalization


No& that 'ou have a #asic $rasp on ho& to create ta#les of data, 'ou face the tas+ of determinin$ &hat $oes &here( %hould all of the data #e on one lar$e ta#le or should the information #e sorted into several smaller ta#les?

)he ans&er is nearl' al&a's the latter @ use multiple ta#les to separate different items( )here are exceptions, of course( If 'ou are creatin$ a =uic+ and dirt' set of data to use for a &ee+, and then thro& a&a', stuffin$ ever'thin$ into one ta#le &ill ma+e the processin$ @ 'our &or+ @ easier( /ut #e carefulJ I once created a set of la#els to invite some customers to a $olf tournament( Five 'ears later, the out$ro&th of that s'stem &as chartin$ the financial course for a >...-person compan'( )he rules for splittin$ up items #et&een ta#les are called normalization( 0ach ta#le 6also called an entity9 contains all of the attri#utes 6fields9 for one item( If an entit' can have more than a =uantit' of one attri#ute 6for example, an order ma' have a series of line items9, then those items $o into a second ta#le( )a#les are related to one another #' a description of ho& information in one ta#le is associated &ith information in another( In the order example, the order num#er is stored in #oth ta#les, and &e can sa' that there is a one-to-many relationship #et&een the ta#lesE one order ma' have man' line items( )he t'pical relations areE one-to-man'E parent to man' children, such as an order to order item Dero-or-one-to man'E a loo+up ta#le ma' #e referenced in none, some or man' other records one-to-oneE data split across several ta#les for performance

)hese relationships defined in the desi$n sta$e &ill not #e of much use if the people usin$ the data#ase s'stem can add, su#tract or modif' data in all of the ta#les &ithout re$ard for the desi$n( For that reason, FoxPro provides relational integrity to the data#ase, throu$h the use of tri$$ers 6code automaticall' fired &hen a data chan$e ta+es place9 and stored procedures 6code stored &ithin the data#ase container9 to enforce the relationships defined on the data(
qualify for Receive

)l)o''is
iClCommPK:I
iEmpFK:I iClientFK:I nClComm*ct:N(-7#)

)lient
iClientPK:I
iIndustFK:I iCliStatFK:I iClCrStaFK:I iCliEn1iFK:I iContactFK:I iBill4oFK:I i&5endaFK:I cClCode:C(!") cCode:C(%) cClName:C('") cCl&ddr!:C(#%) cCl&ddr#:C(#%) cCl&ddr':C(#%) cClCrossSt:C(#%) cClCity:C(!8) cClState:C(#) cCl)ip:C(!") cCl*+one&C:C(') cCl*+one:C(!") cCl*+nE,t:C(-) cClFa,&C:C(') cClFa,No:C(!') cCl6e Site:C(/") cClEmail:C(/") cClContact:C(#%) cClCnt4itl:C(#%) tClStart:4 tClEnd:4 iClNo.fEmp:I cClBillCnct:C(#%) iClIn1Le1l:I lClConsult:L iCl&5enFmt:I iCl&5enCnt:I nClComm:N(-7#) mClNotes:$ nClLast8o :N(/7")

)l)r.tat
describes iClC StaPK:I
cCCCode:C(!") cCC0esc:C(#") lCCInact:L

E'pRecru
iEmpRec PK:I
cEmpRCode:C(!") cEmpR0esc:C('") lEmpRInact:L

E'ployee
recruit iEmpPK:I
iEmpStatFK:I iEmpRaceFK:I iRefByFK:I lEmpBonus:L iEmpClasFK:I iEmpRecrFK:I cEmpCode:C(8) cEmpNum er:C(!") cEmpFirst:C(#") cEmp$idIni:C(!) cEmpLast:C(#%) cEmp&ddr!:C('") cEmp&ddr#:C('") cEmpCity:C(!() cEmpState:C(#) cEmp)ip:C(!") cEmp*+n&C:C(') cEmp*+one:C(8) cEmp*+nE,t:C(-) cEmp&lt&C:C(') cEmp&lt*+n:C(8) cEmp&ltE,t:C(-) cEmpCell&C:C(') cEmpCell*+:C(8) cEmpBeep&C:C(') cEmpBeeper:C(8) cEmpEmail:C(%") lEmp*erm.K:L mEmpNotes:$ cEmp*+oto:C(/") cEmpResume:C(/") dEmpResRec:0 dEmpInter1:0 cEmp2ender:C(!) cEmpS3ills:C(!) cEmp&tt:C(!) cEmp*res:C(!) cEmpSSN:C(!!) dEmp0.B:0 lEmp$edEl:L lEmp$edCo1:L lEmpCautn:L mEmp&1ail:$ cEmp&14erm:C(!) dEmp&1Strt:0 dEmp&1End:0 dEmpLstSp3:0

E'pIndus
have iEmpIndPK:I
iEmpFK:I iIndustFK:I

Industry
describes iIndustPK:I
cIndCode:C(!") cInd0esc:C('") lIndInact:L

Describes

E'pRace
iEmpRacePK:I
cERCode:C(!") cER0esc:C(#") lERInact:L

E'p.kill
iEmpSkilPK:I have
iEmpFK:I iS3illFK:I cES3lLe1el:C(!) iES3lScore:I cES3l0esc:C('") mES3lNotes:$

)li.tat
describes iCliStatPK:I
cCSCode:C(!") cCS0esc:C(#%) lCSInact:L

describes

.kill
describe iSkillPK:I
cS3illCode:C(!") cS3ill0esc:C(/") lS3illInac:L

3ob.kill
make up iJobSkilPK:I
i8o FK:I iS3illFK:I c8SLe1el:C(!)

)liEn%i
Describes iCliEnviPK:I
cCECode:C(!") cCE0esc:C(/") lCEInact:L

E'p.tat
iEmpStatPK:I
cESCode:C(!") cES0esc:C(/") lESInact:L

requires

3ob)ate$
belongs to iJobCatPK:I
c8o CCode:C(!") c8o C0esc:C('%) l8o CInact:L

)liRate
determines iCliRatePK:I
i8o CatFK:I iClientFK:I nCRRate:N(-7#)

describes

Task
iTaskPk:I
c4as3Code:C(!") fills c4as30esc:C(#%) l4as3Inact:L

3ob 3obTask
describe iJobTaskPK:I
i4as3FK:I i8o FK:I

has

iJobPK:I consists of
iClientFK:I i0eptFK:I i8o CIBFK:I i8o SuprFK:I i8o BillFK:I i8o CatFK:I i8o StatFK:I t8o Start:4 t8o End:4 c8o Num:C(!") c8o Rpt4oF:C(!") c8o Rpt4oL:C(!%) c8o Rpt&C:C(') c8o Rpt*+n:C(8) c8o RptE,t:C(-) c8o 0ept:C(/") c8o RptLoc:C(8") m8o Notes:$ c8o 6r3Ld:C(!) n8o *ct*er:N('7") n8o :rs63:N(%7#) c8o 0esc:C(/") c8o RptCmt:C(8") l8o In1Sep:L t8o $odify:4 c8o 9ser:C(!")

E'p)lass
iEmpClasPK:I
cECCode:C(!") cEC0esc:C('") lECInact:L

3ob.tat
describes iJobStatPK:I
c8o StCode:C(!") c8o St0esc:C(#%) l8o StInac:L

defines

Generates

E'p4%ail
iEmpAvPK:I
iEmpFK:I dE&0ate:0 lE&&1ail:L

3ob(uty
consists of iJobDutyPK:I
i0utyFK:I i8o FK:I n80*ercent:N('7")

(uty
describe iDutyPK:I
c0utyCode:C(!") c0uty0esc:C('") l0utyInact:L

have

2ookin$
iBookingPK:I
iEmpFK:I i8o FK:I iCIBFK:I iSuper1FK:I dB36ee3End:0 cB30esc:C(8") lB3SpcSc+d:L tB3Start:4 tB3End:4 lB3Return:L mB3Notes:$ nB3BillRate:N(-7#) nB3*ayRate:N(-7#) lSunRate:L cB3C+30ist:C(!) iB3C+3No:I dE,p&0*:0 dE,pIn1:0 tB3Entry:4 tB3$odify:4 cB39ser:C(!")

can have describes has

Results in

)ontact
iContactPK:I
iClientFK:I iRoleFK:I cCntCode:C(#) cContact:C('") cCntFirst:C(#") cCntLast:C(#") cCnt&ddr!:C('") cCnt&ddr#:C('") cCntCity:C(#%) cCntState:C(#) cCnt)ip:C(!") cCnt*+n&C:C(') cCnt*+one:C(!') cCnt*+nE,t:C(-) cCntFa,&C:C(') cCntFa,:C(!') cCntEmail:C(/") dCnt0.B:0 nCntIn1Lim:N(!"7#)

(ept
iDeptPK:I
iClientFK:I iContactFK:I c0ptCode:C(!") c0ptName:C(/") c0pt&ddr!:C(#") c0pt&ddr#:C(#") c0ptCity:C(#") c0ptState:C(#) c0pt)ip:C(!") c0pt&C:C(') c0pt*+one:C(8) c0pt*+nE,t:C(-)

Receives agenda for Receives nvoices for s the primary contact for

is referred by

supervises is billed for Calls in Calls to create Supervises

can belong to

The ,aury -roup& Inc" Place'ent (ata .yste' II /ctober 10& 1111

2ook(ate
iBookDtPK:I
iBoo3in5FK:I dB0B30ate:0 lB0Boo3ed:L tB0&rri1e:4 tB0Lea1e:4 tB0&ctStrt:4 tB0&ctEnd:4 nB0Lunc+:N('7")

are made up of

Role
iRolePK:I
cRoleCode:C(!") cRole0esc:C('") lRoleInact:L

describe

"uch more information on data desi$n and normaliDation can #e found on the internet or a $ood introductor' text on data#ase desi$n(

Reading and !riting data


Interactive REPLACE, APPEND BLANK, BROWSE, EDIT

VFP Commands REPLACE, APPEND, COP , DELETE S!L Commands INSERT, "PDATE, DELETE

Transactions and buffering


)here are some times in a relationship &hen 'ou are not read' to commit( )here are times &hen chan$es to a relational data#ase should not #e committed, either, perhaps #ecause a chan$e involves multiple ta#les and the chan$es are not 'et complete, or #ecause one of a set of chan$es failed to update properl'( 0nter #ufferin$ and transactions( /ufferin$ allo&s data to #e stored on the local machine until all chan$es are read' to #e made at once( )his prevents t'in$ up shared data resources until the last possi#le minute, and allo&s local processin$ to examine old and ne& values of data 6each stored in a separate #uffer9 to determine ho& a chan$e should #e handled( )ransactions are the other end of the process, once 'ou are read' to commit the data( A transaction loc+s data records as the chan$es are committed, and allo&s the entire set of updates 61a sin$le transaction29 to either #e completed successfull' or rolled #ac+ completel'( Visual FoxPro provides support #oth for local 65/F-#ased9 transaction processin$ and for transaction processin$ in a client-server arran$ement(

Client server data


Why client*ser%er5
)here are three practical reasons to move a 5/F-#ased application to a client-server architectureE Too much dataE VFP has a ph'sical limit of ;K# for a sin$le ta#le or memo file, #ut the limit can often #e hit earlier, &hen the amount of time to PA L or *0IN50A a VFP ta#le exceeds the recover' time of a client server s'stem follo&in$ a crash( As more operations move to&ards ;BxG, this factor has #ecome increasin$l' important( High-security informationE While it is possi#le to crac+ a client-server data#ase, the li+elihood is far $reater in a VFP s'stem &here clients must have access to the underl'in$ ta#les Low bandwidthE VFP &as desi$ned to thrive in a net&or+ environment, and it ta+es advant$e of the lar$e #and&idth to locall' cache file headers, indexes and records( While this results in remar+a#le *ushmore performance on a LAN, it can result in unaccepta#l' slo& performance in a WAN situation( )here are numerous other, more pra$matic reasons to move to a client-server architecture, includin$ the need for flexi#ilit' in distri#utin$ processin$, and the political necessities of some environments(

The 4)I( test 6 4to'icity& )onsistency& Isolation& (urability


"an' or$aniDations 8ustif' their need for a client-server architecture &ith the A I5 test( A &ell-desi$ned client server s'stem meets all of the follo&in$ criteriaE Atomicit'E all data chan$es &ithin a transaction are treated as a sin$le indivisi#le unit, &here all are completed or all are rolled #ac+ as a unit(

onsistenc'E the inte$rit' rules for the data#ase are enforced at all times, so that the data#ase is al&a's in a consistent and valid state( IsolationE results of a transaction are invisi#le until the' are complete, and one transactions intermediate results should not affect another transaction( If one transaction causes the initial conditions of a second transactions to fail, the second transaction should fail( 5ura#ilit'E once the data has #een committed, it &ill #e stored and retrieved even if the s'stem suffers the loss of a hard dis+ or a processor or an' other component that doesnt destro' the s'stem( )ransactions cannot #e 1lost(2

Part 2 6 It+s the codin$


"#$% commands& functions& ob'ect& $()s and design surfaces
A/A%0 commandsE :%0, /*!W%0, *0PLA 0, APP0N5, L! L, 5!, IF, %ML commandsE %0L0 ), IN%0*), 50L0)0, :P5A)0 !utputE ? *0P!*) F!*", N O%A?, AL :LA)0, LI%)I5I%PLA? )ext "anipulationE )extmer$e, LLFF, %trin$ functions A%0

Controls

)ext-#ased controlsE La#el, )ext/ox, 0dit/ox, %pinner Pic+-list controlsE /uttonsE om#o/ox, List/ox hec+/oxes ommand/uttonKroups ommand/uttons, !ption/uttonsKroups,

ontainersC Krids, Pa$eFrames,

Kraphical elementsE Ima$es, Lines, %hapes, %eparators 6tool#ars onl'9 !L0E #oth !L0/ound 6associated &ith data9 and Invisi#le controlE timer ontainer 6! A9 controls

*orking !ith controls


ontrols, in their simplest form, are simpl' the ne& versions of %A?s and K0)s( /ut controls are so much moreJ )he' offer much finer control of the individual o#8ects properties, the a#ilit' to chan$e these properties at run-time, and the a#ilit' to define the code &hich should run &hen an event happens( 0vents are also much more numerous, $ivin$ us the chance to create interfaces more responsive to the user( )he controls supplied &ith Visual FoxPro are the startin$ point( )hese controls can 6and shouldJ9 #e su#classed to create our o&n custom controls( "ultiple controls ma' #e com#ined to form complex controls, #etter reflectin$ the complexit' and #usiness rules of the particular application( ustom controls can #e created, saved and reused(

$roperties
Properties descri#e a characteristic of a control( "ost are availa#le #oth at desi$n and run-time, one exception #ein$ the class properties, &hich are read-onl' &hen the control is created( )hese properties are the data of the control &hich is PencapsulatedP &ith the control( "ost controls share a num#er of common propertiesE )o''on Property )op, 7ei$ht, Left, Width omment Purpose )he location on the form of the o#8ect, if a visual control Pro#a#l' the sin$le most important propert'C letQs 'ou fi$ure out &hat 'ou &ere doin$ &hen 'ou return to it )he pedi$ree of the control 7o& the control is named #' all code &ithin the form &hich refers to it Whether the control should appear /ehavior durin$ mouse dra$ operations ?our hoo+ from the control into 'our custom help file For all text-#ased controls

/ase lass, lass, lassLi#rar' Name

Visi#le 5ra$"ode, 5ra$Icon 7elp ontextI5 FontName, Font%iDe, FontItalic, Font/old, Font!utline, Font%tri+ethrou$h, Font:nderline

olor%cheme, olor%ource, /order olor, Fore olor, 5isa#ledFore olor, /ac+ olor, 5isa#led/ac+ olor

olors(

)hen, there are properties specific to an individual control or t&oE IntervalE ho& often a )imer control fires, %pinner7i$hValue, %pinnerLo&Value, and a sle& of othersJ

E%ents
0vents occur &hen the user has ta+en some action, or pro$rammaticall' &hen a control chan$es status( It is not possi#le to define ne& events( ommon events includeE E%ent Init 5estro' 5ra$5rop, 5ra$!ver Purpose ode run once &hen the control is created ode run &hen the control is released 7o& to #ehave &hen a dra$$ed o#8ect is over and dropped "ouse movement over a control /oth mouse #uttonsJ 7o& errors are handled ode &hen control is ta##ed to or clic+ed on !ur old friends(

"ouse"ove lic+, *i$ht lic+, 5#l lic+, "ouse5o&n, "ouse:p 0rror KotFocus, LostFocus When, Valid

7ethods
"ethods tend to #e more individual to the controls, as the' descri#e the uni=ue #ehavior of the control( )he most common areE 7ethod 5ra$ "ove %etFocus *efresh Purpose What to do if control is dra$$ed "oves controls &ithin a container Pro$rammaticall' PsendP focus to a control 0ach time the control needs

to #e redispla'ed, the code runs( Individual methods include the *eset method for the )imer control, and the 5oVer# methods for the t&o !L0 controls(

7anipulatin$ controls: Property .heet 8 2uilders


Propert' sheets, li+e our demo pro$ram, $ive us access to the various pro$ramma#le and fixed properties, events and methods( /uilders $ive an alternative vie& into a limited num#er of properties, simplif'in$ the construction of o#8ects( Propert' sheets are tools that let us clim# under the hood and t&ea+ all the levers and dials( /uilders donQt have that depth, #ut donQt have the complexit', either(

A Typical Builder

A Pro#ert$ S%eet

)reatin$ your o!n custo' controls


?ou &ill &ant to create 'our o&n set of custom controls so that 'ou can manipulate the #ase classes and modif' their properties and #ehaviors( It is a $ood idea to create a set of Q$enericQ #ut su#classed controls and use these, rather than the standard tool#ar, as the #asis for protot'pin$ screens( reate a custom control #' placin$ a control on a form, hi$hli$htin$ it, then selectin$ Q%ave as class(((P from the PFileP menu( "ost of the literature on the su#8ect of !!P states that it is a learnin$ process, and a different &a' of loo+in$ at pro#lems( Anticipate that 'our first solution ma' not al&a's #e the #est one( If possi#le, protot'pe 'our first development in Visual FoxPro on a s'stem 'ou can thro& a&a'( In su#se=uent s'stems, #e&are of the pro#lem of over-en$ineerin$ a solution( 5onQt #e afraid to thro& out 'our &or+( 5onQt su#class it to death - three or four levels is a#out all 'ouQll comprehend(

(vent model
In 'ears past, FoxPro &as #ased on a procedural model, &hen code started at the top of a procedure and executed line-#'-line until it &as done( "essa$e loops and 1Ketless *0A5s2 could #e used to simulate an event-driven s'stem, #ut there &as a tric+' series of o#scure #ehaviors to $et it to &or+( With the advent of Visual FoxPro, a ne&, clean event model &as introduced that allo&s a much simpler and more comprehensi#le approach to providin$ a trul' event-driven s'stem(

What are E%ents5


PAn action, reco$niDed #' an o#8ect, for &hich 'ou can &rite code to respond( 0vents can #e $enerated #' a user action, such as clic+in$ the mouse or pressin$ a +e', #' pro$ram code, or #' the s'stem, as &ith timers(P + #o,$ro -elp #ile

E%ent irin$ se9uences


Pro#a#l' some of the most difficult functionalit' to understand( )'picall', a container cannot perform its action until its contents exist, therefore, o#8ects are created from the inside outE text#ox@Rcolumn@R$rid@Rpa$e@Rpa$eframe, and destro'ed in the opposite fashion, from the outside in, implodin$(

:o! to pro$ra' or e%ents5


)he Foundation read is no more, except for le$ac' code &e attempt to mi$rate to Visual FoxPro( Forms are it( )he concept #ehind Visual FoxPro is that the initial application environment can #e set up, a menu can #e hoisted to the top of the screen, and *0A5 0V0N)% &ill hold the entire application to$ether until the user chooses to =uit( )ime &ill tell if this model proves ro#ust enou$h for commercial applications( %o &hat are the ne& events? E%ent INI4 4pplies to: &ll; ut;Column7;:eader7; *a5e7;Separator Same & o1e7;plus; Command2roup;and; .ption2roup & o1e7;plus;Cursor7; Custom7; 0ataEn1ironment7; FormSet7;Relation7; 4imer Column7; ut;not;to; a o1e7;plus;.LEControl7; .LEBoundControl Not;to;Column7; ot+er<ise;same;as;a o1e What it does ; !hat to put there Fires;<+en;t+e;o =ect;is;created7;optionally; accepts;parameters>;If;it;returns;>F>7;o =ect;is;not; created>;Contained;o =ects;fire; efore; containers7;in;t+e;order;added> Fires;<+en;an;error;occurs;in;t+e;met+od;of;an; o =ect;-;passes;error;?7;met+od;name;and;line; num er>;Fires; efore;.N;ERR.R> Code;runs;=ust; efore;an;o =ect;is;released>; Containers;fire; efore;contents> Fires;durin5;and;upon;completion;respecti1ely; of;a;dra5;B;drop;operation>;Code;must;include; parameters;statement;to;accept;t+e;dra55ed; o =ect;reference;and;mouse;coordinates> 4rac3s;mouse;mo1ements;o1er;an;o =ect>;&lso; passes;status;of;Ctrl-&lt-S+ift;3eys7;as;<ell;as; left7;middle;and;ri5+t;mouse; utton;statuses> $ouse;clic3

ERR.R 0ES4R.@ 0R&2.AER7; 0R&20R.*

$.9SE$.AE CLICK7;$.9SE0.6N7; $.9SE9*

9IEN&BLE

RI2:4CLICK

2.4F.C9S7; L.S4F.C9S

A&LI07;6:EN

ERR.R$ESS&2E

$ESS&2E KE@*RESS

C+ec3Bo,7;Com oBo,7; CommandButton7; Command2roup7; Container7;Control7; EditBo,7;2rid7;Ima5e7; La el7;Line7;ListBo,7; .LEBoundControl7; .LEControl7; .ption2roup7; *a5eFrame7;S+ape7; Spinner7;4e,tBo, & o1e7;plus;Form7; :eader7;.ptionButton7; .ption2roup7; ut;N.4; .LEBoundControl7; .LEControl C+ec3Bo,7;Com oBo,7; CommandButton7; Container7;Control7; EditBo,7;Form7; ListBo,7; .LEBoundControl7; .LEControl7; .ptionButton7;Spinner7; 4e,tBo, C+ec3Bo,7;Com oBo,7; CommandButton7; Command2roup7; EditBo,7;2rid7;;ListBo,7; .ptionButton7; .ption2roup7;Spinner7; 4e,tBo, C+ec3Bo,7;Com oBo,7; CommandButton7; Command2roup7; EditBo,7;ListBo,7; .ptionButton7; .ption2roup7;Spinner7; 4e,tBo, same;as;a o1e C+ec3Bo,7;Com oBo,7; CommandButton7; EditBo,7;Form7;ListBo,7; .ptionButton7;Spinner7; 4e,tBo, Column7;Container7; Control7;Form7;2rid7; .LEBoundControl7; .LEControl7; *a5eFrame7;4ool ar same;

Fires;<+en;control; ecomes;1isi le; ecause;of; acti1ation;of;container7;suc+;as;*a5eFrame>

Ri5+t;mouse;clic3;on;control>

.ccurs;<+en;t+e;control;is;ta

ed;to7;or;clic3ed; on>

2ood;old;6:EN;and;A&LI07;fire; efore; acceptin5;a;c+an5e;(after;recei1in5;focus);and; after;a;c+an5e;is;made>

6+en;A&LI0;returns;a;>F>7;allo<s;display;of;an; error;messa5e>;CIncluded;for; ac3<ard; compati ilityC

0isplays;status; ar;te,t>;&not+er;C; ac3<ard; compati ility>C;*roperty;StatusBar4e,t;pro1ides; similar;capa ilities> &llo<s;processin5;of;input;3eystro3e- y3eystro3e7;rat+er;t+an;<aitin5;for;input;to; e; completed> Fires;<+en;t+e;o =ect;+as; een;mo1ed>

$.AE0

RESI)E

Fires;<+en;t+e;o =ect;+as; een;resiDed>

Interacti1eC+an5e7; *ro5rammaticC+an5e

C+ec3Bo,7;Com oBo,7;7; Command2roup7; EditBo,7;ListBo,7; .ption2roup7;Spinner7; 4e,tBo, Form7;FormSet7;*a5e7; 4ool ar Com oBo,7;List o,7; Spinner7;4e,tBo,

&C4IA&4E7; 0E&C4IA&4E R&N2E:I2:7; R&N2EL.6

0.6NCLICK L.&07;9NL.&0 *&IN4 BEF.RE.*EN4&BLES7; &F4ERCL.SE4&BLES &F4ER0.CK7; BEF.RE0.CK7; 9N0.CK7 BeforeRo<ColC+an5e7; &fterRo<ColC+an5e 0ELE4E0 SCR.LLE0 0R.*0.6N 4I$ER G9ER@9NL.&0 RE&0&C4IA&4E7; RE&00E&C4IA&4E7; RE&0S:.67; RE&0A&LI07; RE&06:EN

Com oBo,7;ListBo,7; Spinner Form7;FormSet Form7;4ool ar 0ata;En1ironment 4ool ar 2rid 2rid 2rid Com oBo, 4imer Form Form

6+at;9*0&4E0();al<ays;s+ould;+a1e; een7; ut;at;a;finer;le1el>;Fires;eac+;time;a;c+an5e;is; made;1ia;mouse;or;3ey oard7;e1en; efore;focus; +as;s+ifted;from;t+e;control>;IN4ER&C4IAE; detects;user;c+an5es7;*R.2R&$$&4IC; c+an5es;performed;in;code> Similar;to;t+e;#>,;ScreenEs;s+o<;clause>;.ccurs; <+en;container;5ets;t+e;focus;or;S+o<();met+od; runs>;4ool ar>:ide();also;runs;0E&C4IA&4E; 0ual;functions>;For;Com oBo,;and;ListBo,7; returns;t+e;initially;selected;element;<+en;t+e; control;5ets;t+e;focus>;For;Spinners;B; 4e,tBo,es;acts;as;a;R&N2E;test7;returnin5;a; numeric;<+en;focus;to;t+e;control;is;lost> Not;to; e;confused;<it+;$.9SE0.6N7;fires; <+en;t+e;do<n-;or;up-<ard-pointin5;arro<;is; pressed> Load;occurs;after;Init7; ut; efore;&cti1ate;and; 2otFocus>;9nLoad;is;t+e;last;e1ent;to;fire> 6+en;t+e;item;re-paints>;C&94I.N:;donEt; RESI)E;or;refres+();o =ects;<it+in;*&IN4;or;a; Ccascadin5C;series;may;occurF 6rappers;around;t+e;automatic; e+a1ior;of;t+e; 0ata;En1ironment>;.ccurs; efore;.pen4a les(); met+od;and;after;Close4a les();met+ods> Code;<+ic+;can;run;<+ile;user;is;manipulatin5; a;tool ar> Before;t+e;Aalid;of;t+e;ro<;or;column;of;t+e; cell; ein5;left7;and;after;t+e;6+en;of;t+e;cell; ein5;mo1ed;to> 6+en;user;mar3s;or;unmar3s;a;ro<;for;deletion> 9ser;mo1ement7;parameter;<ill;return;<+et+er; y;cursor;3eys;or;scroll; ars;and;<+ic+;one> Fires;after;0.6NCLICK7;to;allo<;interacti1e; c+an5es;to;t+e;contents;of;t+e;drop;do<n;list> Fires;<+en;4imer;is;ena led;and;Inter1al;+as; passed> &llo<s;testin5;t+e;Release4ype;property;to; determine;if;a;form;is; ein5;released;usin5;t+e; close; o,;or;pro5rammatically> Similar;to;#>,;RE&0;model7;only;<or3s;in; ECompati ilityE;modes

What to do no!5
0xperiment( 4.S of the time the standard W70N and VALI5 &ill provide all the functionalit' needed in data entr' fields( %pecialiDed input fields, such as %pinners, have finer control( lic+ is a more intuitive place to put #utton-firin$ code than VALI5, #ut either 6thou$h not necessaril' #othJ9 &or+( Add ne& 0vents to 'our arsenal as the

need arises( Anticipate some $reat third part' tools that +no& ho& to reall' ta+e advanta$e of all the ne& features(

The tools

Pro8ect "ana$ers ode 0ditor Form 5esi$ner lass 5esi$ner "enu 5esi$ner

Part III: 4d%anced topics


!#8ect oriented anal'sis and desi$n !" and n-tier desi$n :ser Interface 5esi$n Pro8ect "ana$ement

Part IV: Puttin$ it all to$ether


*)F" @ VFP comes &ith an excellent set of resources( /ro&se the help file( )here is a tremendous amount of &ell-or$aniDed material there( 5ont fi$ht the tide( Learn to #ecome one &ith the Fox #' thin+in$ the &a' the Fox thin+s( Ket a frame&or+ Ket a support $roupE mailin$ lists, online communities, ma$aDines T ne&sletters %harpen the sa& @ #oo+s and conferences )op )en "ista+es

.bout the .uthor


)ed *oche is president of )ed *oche T Associates, LL , a consultin$ firm #ased in Ne& 7ampshire( 7e is author of Essential SourceSafe, co-author &ith )amar Kranor of the Ted Roche a&ard-&innin$ Hacker's Guide to Visual FoxPro 6, and a contri#utor to < other FoxPro #oo+s( A former ontri#utin$ Associates 0ditor for FoxPro Advisor ma$aDine, )ed is a "icrosoft ! LL" ertified %olution 5eveloper, %'stems 0n$ineer and seventime "icrosoft %upport "ost Valua#le Professional( ontact )ed at tedrocheNtedroche(com Ted Roche

References
"' 3<-'ear immersion in Fox soft&are and the other d/A%0 variants &ould have #een a much shallo&er and &ea+er experience had it not #een for the thrivin$ online communities @ ompu%erve, the Fox Wi+i, the ProFox mailin$ list @ that have #rou$ht depth and meanin$ and humanit' to the experience( )han+s to all of those &ho participated( If 'ou are not 'et involved in an online communit', find one and, at the

least, lur+ in the #ac+$round for a &hile( )he support and education is invalua#le, at a ver' reasona#le cost(

/nline co''unities
Nearl' the $randdadd' of them all, ompu%erve has opened their forums to the &e#( %tart at httpEII&&&(compuserve(com, and $o from there( A direct lin+ that &or+s for me is httpEII$o(compuserve(comI"%5evApps?locUus - 'our milea$e ma' var'( Pro#a#l' the most active FoxPro communit' on the &e# toda' is httpEII&&&(universalthread(com, &ith man' &ell-+no&n authors and spea+ers fre=uentin$ the site( A close runner-up is the repositor' of +no&led$e #uilt up #' its mem#ers at httpEIIfox(&i+is(com - a remar+a#le, or$anic site that allo&s visitors to add, edit and enhance the existin$ &e# site( /ut there are a num#er of other &orth&hile sites( *od Paddoc+ hosts httpEII&&&(foxforum(com ( 0d Leafe hosts the ProFox mailin$ listC 'ou can si$n up at httpEII&&&(leafe(com, and the Virtual FoxPro :ser Kroup is online at httpEII&&&(vfu$(or$I(

2ooks
Im a #i$ advocate of learnin$ #' readin$( )here are a lot of fascinatin$ #oo+s out there, and I am al&a's in the process of readin$ a fe& at a time( If this isnt 'our st'le, consider han$in$ around &ith people &ho are +eepin$ up &ith the latest #oo+s @ #' visitin$ their &e# sites, listenin$ to them at conferences and user $roup meetin$s, or &or+in$ &ith them( %teven /lac+ has an extensive readin$ list at httpEII&&&(steven#lac+(com - loo+ for 1#oo+shelf(2 Whil 7entDen maintains another list at httpEII&&&(hentDen&er+e(com his is called 1)he %tac+s(2 /et&een those t&o lists alone, 'ou &ill find most, if not all, of the #oo+s I &ould recommend as &ell(

7a$a<ines
FoxPro devotees should +eep up on &hats happenin$ in the FoxPro &orld #' readin$ ever'thin$ thats availa#le out there( !f course, that &ould mean that there &ould #e no time left for other activities, li+e pro$rammin$, or sleep, or this 1life2 thin$ I +eep hearin$ a#out( "' advice is to su#scri#e to all the ma$aDines that interest 'ou and at least s+im the ta#le of contents( )hat &a', 'ou can read the articles that essential for 'ou to +no& ri$ht no&, and store a&a' +no&led$e that there are other articles 'ou can $et #ac+ to later( Fox)al+ 6httpEII&&&(pinnaclepu#lishin$(comIft9 and FoxPro Advisor 6httpEII&&&(advisor(comI&&&IFoxProAdvisor9 are the leadin$ ma$aDines in the field(

=ser -roups
A user $roup t'picall' meets one evenin$ a &ee+ to s&ap stories, net&or+, demonstrate some code or product, and support each other( )hese offer a $reat chance to $et out of the house, meet &ith people of similar interests, find ne& 8o#s, locate consultants or consultin$ opportunities, and +eep up &ith &hat is $oin$ on in the industr'( )here are lists of user $roups at httpEIIfox(&i+is(comI&c(dll? Wi+iV ate$or':serKroups, httpEII&&&(#ostonuser$roups(com, or hit 'our favorite search en$ine to locate a $roup near 'ou? No $roups near#'? %tart 'our o&nJ

,inks
&n;e,cellent;e,planation;of;t+e;&CI0;principles;is;a1aila le;on; & !ttp:""###$a sdigita$com"books"panda"databases%c!oosing && & Lammers, %usan, Programmers at Work "icrosoft Press, 34-F, features a fascinatin$ intervie& &ith Wa'ne *atliff 6&hile he had an office at Ashton-)ate, and the I/" A) &as considered a #ar$ain at HF,...9 dBASE is a re&istered trademar' o( dBASE Inc) Ot%er dBASE Inc) #rod*ct names are trademar's or re&istered trademar's o( dBASE Inc) !ri$inall' presented as a pre-conference session at the FoxPro 5ev ;..3, %an 5ie$o, A, %eptem#er -, ;..3( op'ri$ht + ;..3-;..- #' )ed *oche( )his &or+ is licensed under the reative ommons Attri#ution-Noncommercial-%hare Ali+e >(. :nited %tates License( )o vie& a cop' of this license, visit httpEIIcreativecommons(or$IlicensesI#'-nc-saI>(.IusI or send a letter to reative ommons, 3G3 %econd %treet, %uite >.., %an Francisco, alifornia, 4B3.<, :%A(

Vous aimerez peut-être aussi