PRE201

Embed Size (px)

Citation preview

  • 8/13/2019 PRE201

    1/16

    PRE201: Introduction to Visual FoxPro

    This Workshop introduces you to Visual FoxPro and thebasics 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 !orkedin Visual FoxPro beore& and you !ould like to $et 'ore out

    o the (e%)on that ollo!s"

    In the be$innin$& !as the dotWhat is Visual FoxPro?

    Its a standalone tool for data manipulation

    Its a development tool for standalone, LAN, client-server, !" and We#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

    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 thosestatements( )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'ledata#ase en$ine and manipulation lan$ua$e on his I"%AI .. computer, inassem#ler, in his spare time, in order to improve his chances in the foot#all pool( !nethin$ lead to another, and he &as soon mar+etin$ the product as d/A%0( It &aspurchased #' Ashton-)ate, then /orland, and is no& o&ned #' d/A%0, Inc( It &as onethe +e' products in the ma+in$ of the 1P *evolution2 of the 34.s that lead to a Pon ever' des+( In its he'da', a num#er of lan$ua$e-compati#le 1clones2 such asFox/ase, lipper, d#"AN and man' others competed fiercel' for the hearts andminds 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 5evoncontinues to this da'(9 Fox %oft&are created a fast, interpreted version of the d/A%0runtime 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 ;(

  • 8/13/2019 PRE201

    2/16

    apprentice, and 8ourne'man to reach the master level( Achievin$ master' is not asu#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 coverhere( First, I loo+ at data, as is it the data that is reall' &hat it is all a#out @ theapplication is 8ust a &a' to #etter mana$e the data( %econd, I loo+ at the lan$ua$eitself, 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 ando#8ects that #uild applications( Finall', the fourth section tries to pull to$ether all ofthe previous sections, and provide a perspective and philosoph' of ho& an entireapplication 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 fieldis 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 #esu#-divided &hen 'ou are processin$( For example, if 'our part num#er is composedof a part t'pe, a re$ion code, a ratin$ and a su#-part num#er, such as AN->>-B-3;>B, it can often #e #etter to #rea+ that information into separate fields andcom#ine it &hen needed, rather than tr' to #e constantl' splittin$ the field &henloo+in$ for all parts from one re$ion(

    0ach field has a sin$le datatype( 5ata t'pes hold a particular +ind of informationChave upper and lo&er limits on their capacit'C and are restricted on &hat informationthe' can hold( Fields ma' #e character, inte$er, date, datetime 6a com#ination ofdate 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 !L0information 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 toform a record( For example, 'ou mi$ht record a chec+ received from a customer asE

    Field name Type Data

    ustomerNum#er

    Inte$er B>;3

    hec+ Num#er Inte$er

  • 8/13/2019 PRE201

    3/16

    3;B> >3;3 ;>; .3.334.3

    >;>; B>;B>

    >>B> .;.;;..;

    ;>;>; B; B>(>B .>.>34

    .>

    )his $eometr' leads to other names for the items, records are often called rowsandfields columns.

    In FoxPro, there are usuall' three &a's to do an'thin$, or no &a' at all( )o create thista#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)

    !rEDIMENSION 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#$+,+' 9a!"e#$+,%' 2a!"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 iseasiest 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 mostflexi#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+ ofdeterminin$ &hat $oes &here( %hould all of the data #e on one lar$e ta#le or shouldthe information #e sorted into several smaller ta#les?

  • 8/13/2019 PRE201

    4/16

    )he ans&er is nearl' al&a's the latter @ use multiple ta#les to separate differentitems( )here are exceptions, of course( If 'ou are creatin$ a =uic+ and dirt' set ofdata to use for a &ee+, and then thro& a&a', stuffin$ ever'thin$ into one ta#le &illma+e the processin$ @ 'our &or+ @ easier( /ut #e carefulJ I once created a set ofla#els to invite some customers to a $olf tournament( Five 'ears later, the out$ro&thof 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#le6also 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 aseries of line items9, then those items $o into a second ta#le( )a#les are relatedtoone another #' a description of ho& information in one ta#le is associated &ithinformation in another( In the order example, the order num#er is stored in #othta#les, and &e can sa' that there is a one-to-manyrelationship #et&een the ta#lesEone 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 orman' 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 peopleusin$ 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 integritytothe data#ase, throu$h the use of tri$$ers 6code automaticall' fired &hen a datachan$e ta+es place9 and stored procedures 6code stored &ithin the data#asecontainer9 to enforce the relationships defined on the data(

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

    have describe

    has

    isreferred by

    describes hasdetermines

    Generates

    Resultsin

    defines

    Describes

    belongsto

    can have

    requires

    makeup

    describeconsistsof

    have describes

    can belong to

    describes

    describe

    describes

    describe consistsof

    have

    describes

    describes

    describes

    fills

    aremadeup ofCalls to create

    Supervises

    Callsin

    supervises

    isbill ed for

    recruit

    Receive

    qualifyfor

    Receivesagendafor

    Receivesnvoicesfor

    sthe primarycontact for

    Describes

    iEmpPK:I

    iEmpStatFK:I

    iEmpRaceFK:I

    iRefByFK:I

    lEmpBonus:L

    iEmpClasFK:I

    iEmpRecrFK:I

    cEmpCode:C(8)

    cEmpNumer:C(!")

    cEmpFirst:C(#")

    cEmp$idIni:C(!)

    cEmpLast:C(#%)

    cEmp&ddr!:C('")

    cEmp&ddr#:C('")

    cEmpCity:C(!)

    cEmpState:C(#)

    cEmpip: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'ployee

    )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(#)

    cClip:C(!")

    cCl*+one&C:C(')

    cCl*+one:C(!")

    cCl*+nE,t:C(-)

    cClFa,&C:C(')

    cClFa,No:C(!')

    cCl6eSite: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:$

    nClLasto:N(/7")

    iSkillPK:I

    cS3illCode:C(!")

    cS3ill0esc:C(/")

    lS3illInac:L

    .killiEmpSkilPK:I

    iEmpFK:I

    iS3illFK:I

    cES3lLe1el:C(!)

    iES3lScore:IcES3l0esc:C('")

    mES3lNotes:$

    E'p.kill

    iContactPK:I

    iClientFK:I

    iRoleFK:I

    cCntCode:C(#)

    cContact:C('")

    cCntFirst:C(#")

    cCntLast:C(#")

    cCnt&ddr!:C('")

    cCnt&ddr#:C('")

    cCntCity:C(#%)

    cCntState:C(#)

    cCntip:C(!")

    cCnt*+n&C:C(')

    cCnt*+one:C(!')

    cCnt*+nE,t:C(-)

    cCntFa,&C:C(')

    cCntFa,:C(!')

    cCntEmail:C(/")

    dCnt0.B:0nCntIn1Lim:N(!"7#)

    )ontact

    2ook(ate

    iBookDtPK:I

    iBoo3in5FK:I

    dB0B30ate:0

    lB0Boo3ed:L

    tB0&rri1e:4

    tB0Lea1e:4

    tB0&ctStrt:4

    tB0&ctEnd:4

    nB0Lunc+:N('7")

    iJobCatPK:I

    coCCode:C(!")

    coC0esc:C('%)

    loCInact:L

    3ob)ate$

    iBookingPK:I

    iEmpFK:I

    ioFK: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(!")

    2ookin$

    E'p.tat

    iEmpStatPK:I

    cESCode:C(!")

    cES0esc:C(/")

    lESInact:L

    iCliRatePK:I

    ioCatFK:I

    iClientFK:I

    nCRRate:N(-7#)

    )liRate

    iJobPK:I

    iClientFK:I

    i0eptFK:I

    ioCIBFK:I

    ioSuprFK:I

    ioBillFK:I

    ioCatFK:I

    ioStatFK:I

    toStart:4

    toEnd:4

    coNum:C(!")

    coRpt4oF:C(!")

    coRpt4oL:C(!%)

    coRpt&C:C(')

    coRpt*+n:C(8)

    coRptE,t:C(-)

    co0ept:C(/")

    coRptLoc:C(8")

    moNotes:$

    co6r3Ld:C(!)

    no*ct*er:N('7")

    nors63:N(%7#)

    co0esc:C(/")

    coRptCmt:C(8")

    loIn1Sep:L

    to$odify:4

    co9ser:C(!")

    3ob

    iEmpClasPK:I

    cECCode:C(!")

    cEC0esc:C('")

    lECInact:L

    E'p)lass

    iIndustPK:I

    cIndCode:C(!")

    cInd0esc:C('")

    lIndInact:L

    Industry

    iJobSkilPK:I

    ioFK:I

    iS3illFK:I

    cSLe1el:C(!)

    3ob.kill

    (uty

    iDutyPK:I

    c0utyCode:C(!")

    c0uty0esc:C('")

    l0utyInact:L

    (ept

    iDeptPK:I

    iClientFK:I

    iContactFK:I

    c0ptCode:C(!")

    c0ptName:C(/")

    c0pt&ddr!:C(#")

    c0pt&ddr#:C(#")

    c0ptCity:C(#")

    c0ptState:C(#)

    c0ptip:C(!")

    c0pt&C:C(')

    c0pt*+one:C(8)

    c0pt*+nE,t:C(-)

    iJobDutyPK:I

    i0utyFK:I

    ioFK:I

    n0*ercent:N('7")

    3ob(uty

    iEmpIndPK:I

    iEmpFK:I

    iIndustFK:I

    E'pIndus

    iRolePK:I

    cRoleCode:C(!")

    cRole0esc:C('")

    lRoleInact:L

    Role

    iJobStatPK:I

    coStCode:C(!")

    coSt0esc:C(#%)

    loStInac:L

    3ob.tat

    iTaskPk:I

    c4as3Code:C(!")

    c4as30esc:C(#%)

    l4as3Inact:L

    Task

    iJobTaskPK:I

    i4as3FK:I

    ioFK:I

    3obTask

    iEmpAvPK:I

    iEmpFK:I

    dE&0ate:0

    lE&&1ail:L

    E'p4%ail

    iCliStatPK:I

    cCSCode:C(!")

    cCS0esc:C(#%)

    lCSInact:L

    )li.tat

    iEmpRacePK:I

    cERCode:C(!")

    cER0esc:C(#")

    lERInact:L

    E'pRace

    iClCStaPK:I

    cCCCode:C(!")

    cCC0esc:C(#")

    lCCInact:L

    )l)r.tat

    iEmpRecPK:I

    cEmpRCode:C(!")

    cEmpR0esc:C('")

    lEmpRInact:L

    E'pRecru

    iClCommPK:I

    iEmpFK:I

    iClientFK:I

    nClComm*ct:N(-7#)

    )l)o''is

    iCliEnviPK:I

    cCECode:C(!")

    cCE0esc:C(/")

    lCEInact:L

    )liEn%i

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

    Reading and !riting data

    Interactive

    REPLACE, APPEND BLANK, BROWSE, EDIT

  • 8/13/2019 PRE201

    5/16

    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 aretimes &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 'etcomplete, 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#leminute, and allo&s local processin$ to examine old and ne& values of data 6eachstored 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 theentire set of updates 61a sin$le transaction29 to either #e completed successfull' orrolled #ac+ completel'( Visual FoxPro provides support #oth for local 65/F-#ased9transaction 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-serverarchitectureE

    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 or *0IN50 a VFPta#le exceeds the recover' time of a client server s'stem follo&in$ a crash( As moreoperations 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 theunderl'in$ ta#les

    Low bandwidthE VFP &as desi$ned to thrive in a net&or+ environment, and it ta+esadvant$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 inunaccepta#l' slo& performance in a WAN situation(

    )here are numerous other, more pra$matic reasons to move to a client-serverarchitecture, 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 AI5test( 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#leunit, &here all are completed or all are rolled #ac+ as a unit(

  • 8/13/2019 PRE201

    6/16

    onsistenc'E the inte$rit' rules for the data#ase are enforced at all times, so that thedata#ase is al&a's in a consistent and valid state(

    IsolationE results of a transaction are invisi#le until the' are complete, and onetransactions intermediate results should not affect another transaction( If onetransaction causes the initial conditions of a second transactions to fail, the secondtransaction should fail(

    5ura#ilit'E once the data has #een committed, it &ill #e stored and retrieved even ifthe s'stem suffers the loss of a hard dis+ or a processor or an' other component thatdoesnt destro' the s'stem( )ransactions cannot #e 1lost(2

    Part 6 It+s the codin$

    "#$% commands& functions& ob'ect& $()s and design surfaces

    /A%0 commandsE :%0, /*!W%0, *0PLA0, APP0N5, L!, 5!, IF, A%0

    %ML commandsE %0L0), IN%0*), 50L0)0, :P5A)0

    !utputE ? *0P!*) F!*", O%A, AL:LA)0, LI%)5I%PLA

    )ext "anipulationE )extmer$e, LLFF, %trin$ functions

    Controls

    )ext-#ased controlsE La#el, )ext/ox, 0dit/ox, %pinner

    Pic+-list controlsE om#o/ox, List/ox

    /uttonsE ommand/uttons, !ption/uttonsKroups, hec+/oxes

    ontainersC Krids, Pa$eFrames, ommand/uttonKroups

  • 8/13/2019 PRE201

    7/16

    Kraphical elementsE Ima$es, Lines, %hapes, %eparators 6tool#ars onl'9

    !L0E #oth !L0/ound 6associated &ith data9 and ontainer 6!9 controls

    Invisi#le controlE timer

    *orking !ith controls

    ontrols, in their simplest form, are simpl' the ne& versions of %As and K0)s( /utcontrols are so much moreJ )he' offer much finer control of the individual o#8ectsproperties, the a#ilit' to chan$e these properties at run-time, and the a#ilit' todefine the code &hich should run &hen an event happens( 0vents are also muchmore numerous, $ivin$ us the chance to create interfaces more responsive to theuser(

    )he controls supplied &ith Visual FoxPro are the startin$ point( )hese controls can6and 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 #usinessrules 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$nand run-time, one exception #ein$ the class properties, &hich are read-onl' &hen thecontrol is created( )hese properties are the data of the control &hich isencapsulated &ith the control( "ost controls share a num#er of commonpropertiesE

    )o''on Property Purpose

    )op, 7ei$ht, Left, Width )he location on the form ofthe o#8ect, if a visual control

    omment Pro#a#l' the sin$le most

    important propert'C letQs 'oufi$ure out &hat 'ou &eredoin$ &hen 'ou return to it

    /aselass, lass,lassLi#rar'

    )he pedi$ree of the control

    Name 7o& the control is named #'all code &ithin the form&hich refers to it

    Visi#le Whether the control shouldappear

    5ra$"ode, 5ra$Icon /ehavior durin$ mouse dra$

    operations

    7elpontextI5 our hoo+ from the controlinto 'our custom help file

    FontName, Font%iDe,FontItalic, Font/old,Font!utline,Font%tri+ethrou$h,Font:nderline

    For all text-#ased controls

  • 8/13/2019 PRE201

    8/16

    olor%cheme, olor%ource,/orderolor, Foreolor,5isa#ledForeolor,/ac+olor,5isa#led/ac+olor

    olors(

    )hen, there are properties specific to an individual control or t&oE IntervalE ho& oftena )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 acontrol chan$es status( It is not possi#le to define ne& events( ommon eventsincludeE

    E%ent PurposeInit ode run once &hen the

    control is created

    5estro' ode run &hen the control isreleased

    5ra$5rop, 5ra$!ver 7o& to #ehave &hen adra$$ed o#8ect is over anddropped

    "ouse"ove "ouse movement over acontrol

    lic+, *i$htlic+, 5#llic+,

    "ouse5o&n, "ouse:p

    /oth mouse #uttonsJ

    0rror 7o& errors are handled

    KotFocus, LostFocus ode &hen control is ta##edto or clic+ed on

    When, Valid !ur old friends(

    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 Purpose

    5ra$ What to do if control isdra$$ed

    "ove "oves controls &ithin acontainer

    %etFocus Pro$rammaticall' sendfocus to a control

    *efresh 0ach time the control needs

  • 8/13/2019 PRE201

    9/16

    to #e redispla'ed, the coderuns(

    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 uilders

    Propert' sheets, li+e our demo pro$ram, $ive us access to the various pro$ramma#leand fixed properties, events and methods( /uilders $ive an alternative vie& into alimited 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 leversand dials( /uilders donQt have that depth, #ut donQt have the complexit', either(

    A Typical Builder

  • 8/13/2019 PRE201

    10/16

    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 manipulatethe #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 thestandard 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((( from theFile menu(

    "ost of the literature on the su#8ect of !!P states that it is a learnin$ process, and adifferent &a' of loo+in$ at pro#lems( Anticipate that 'our first solution ma' notal&a's #e the #est one( If possi#le, protot'pe 'our first development in Visual FoxProon a s'stem 'ou can thro& a&a'( In su#se=uent s'stems, #e&are of the pro#lem ofover-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 topof a procedure and executed line-#'-line until it &as done( "essa$e loops and 1Ket-less *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 morecomprehensi#le approach to providin$ a trul' event-driven s'stem(

  • 8/13/2019 PRE201

    11/16

    What are E%ents5

    An action, reco$niDed #' an o#8ect, for &hich 'ou can &rite code to respond( 0ventscan #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(

    + #o,$ro -elp #ile

    E%ent irin$ se9uences

    Pro#a#l' some of the most difficult functionalit' to understand( )'picall', a containercannot perform its action until its contents exist, therefore, o#8ects are created fromthe inside outE text#ox@Rcolumn@R$rid@Rpa$e@Rpa$eframe, and destro'ed in theopposite 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 toVisual FoxPro( Forms are it( )he concept #ehind Visual FoxPro is that the initialapplication environment can #e set up, a menu can #e hoisted to the top of thescreen, and *0A5 0V0N)% &ill hold the entire application to$ether until the userchooses to =uit( )ime &ill tell if this model proves ro#ust enou$h for commercialapplications(

    %o &hat are the ne& events?

    E%ent 4pplies to: What it does ; !hat to put thereINI4 &ll ut Column7 eader7

    *a5e7 Separator

    Fires If it returns >F>7 o=ect is not

    created> Contained o=ects fire efore

    containers7 in t+e order added>

    ERR.R Same Fires Fires efore .N ERR.R>

    0ES4R.@ &o1e7 plusCommand2roup and

    .ption2roup

    Code runs =ust efore an o=ect is released>Containers fire efore contents>

    0R&2.AER7

    0R&20R.*

    &o1e7 plus Cursor7

    Custom7

    0ataEn1ironment7

    FormSet7 Relation7

    4imer

    Fires durin5 and upon completion respecti1ely

    of a dra5 drop operation> Code must include

    parameters statement to accept t+e dra55ed

    o=ect reference and mouse coordinates>

    $.9SE$.AE Column7 ut not to

    ao1e7 plus .LEControl7

    .LEBoundControl

    4rac3s mouse mo1ements o1er an o=ect> &lso

    passes status of Ctrl-&lt-S+ift 3eys7 as

    CLICK7 $.9SE0.6N7

    $.9SE9*

    Not to Column7

    ot+er

  • 8/13/2019 PRE201

    12/16

    9IEN&BLE C+ec3Bo,7 ComoBo,7

    CommandButton7

    Command2roup7

    Container7 Control7

    EditBo,7 2rid7 Ima5e7Lael7 Line7 ListBo,7

    .LEBoundControl7.LEControl7

    .ption2roup7

    *a5eFrame7 S+ape7

    Spinner7 4e,tBo,

    Fires

    RI24CLICK &o1e7 plus Form7

    eader7 .ptionButton7

    .ption2roup7 ut N.4

    .LEBoundControl7

    .LEControl

    Ri5+t mouse clic3 on control>

    2.4F.C9S7

    L.S4F.C9S

    C+ec3Bo,7 ComoBo,7

    CommandButton7

    Container7 Control7EditBo,7 Form7

    ListBo,7

    .LEBoundControl7

    .LEControl7

    .ptionButton7 Spinner7

    4e,tBo,

    .ccurs

    A&LI07 6EN C+ec3Bo,7 ComoBo,7

    CommandButton7

    Command2roup7

    EditBo,7 2rid7 ListBo,7

    .ptionButton7

    .ption2roup7 Spinner74e,tBo,

    2ood old 6EN and A&LI07 fire efore

    acceptin5 a c+an5e (after recei1in5 focus) and

    after a c+an5e is made>

    ERR.R$ESS&2E C+ec3Bo,7 ComoBo,7

    CommandButton7Command2roup7

    EditBo,7 ListBo,7

    .ptionButton7

    .ption2roup7 Spinner7

    4e,tBo,

    6+en A&LI0 returns a >F>7 allo Included for ac3 &not+er ac3 *roperty StatusBar4e,t pro1ides

    similar capailities>

    KE@*RESS C+ec3Bo,7 ComoBo,7

    CommandButton7

    EditBo,7 Form7 ListBo,7

    .ptionButton7 Spinner7

    4e,tBo,

    &llo

  • 8/13/2019 PRE201

    13/16

    Interacti1eC+an5e7

    *ro5rammaticC+an5e

    C+ec3Bo,7 ComoBo,7 7

    Command2roup7

    EditBo,7 ListBo,7

    .ption2roup7 Spinner7

    4e,tBo,

    6+at 9*0&4E0() al Fires eac+ time a c+an5e is

    made 1ia mouse or 3eyoard7 e1en efore focus

    +as s+ifted from t+e control> IN4ER&C4IAE

    detects user c+an5es7 *R.2R&$$&4ICc+an5es performed in code>

    &C4IA&4E70E&C4IA&4E Form7 FormSet7 *a5e74oolar Similar to t+e #>, Screens s+o< clause> .ccurside() also runs 0E&C4IA&4E

    R&N2EI27

    R&N2EL.6

    ComoBo,7 Listo,7

    Spinner7 4e,tBo,

    0ual functions> For ComoBo, and ListBo,7

    returns t+e initially selected element For Spinners

    4e,tBo,es acts as a R&N2E test7 returnin5 a

    numeric

    0.6NCLICK ComoBo,7 ListBo,7

    Spinner

    Not to e confused C&94I.N: dontRESIE or refres+() o=ects .ccurs efore .pen4ales()

    met+od and after Close4ales() met+ods>

    &F4ER0.CK7

    BEF.RE0.CK7

    9N0.CK7

    4oolar Code

  • 8/13/2019 PRE201

    14/16

    need arises( Anticipate some $reat third part' tools that +no& ho& to reall' ta+eadvanta$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 atremendous amount of &ell-or$aniDed material there(

    5ont fi$ht the tide( Learn to #ecome one &ith the Fox #' thin+in$ the &a' the Foxthin+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

    Ted Roche

    Ted Roche

    Associates! LL"

    )ed *oche is president of)ed *oche T Associates, LL, aconsultin$ firm #ased in Ne& 7ampshire( 7e is author ofEssential SourceSafe, co-author &ith )amar Kranor of thea&ard-&innin$ Hacker's Guide to Visual FoxPro 6, and acontri#utor to < other FoxPro #oo+s( A former ontri#utin$0ditor for FoxPro Advisor ma$aDine, )ed is a "icrosoftertified %olution 5eveloper, %'stems 0n$ineer and seven-time "icrosoft %upport "ost Valua#le Professional( ontact

    )ed at tedrochetedroche(com

    References

    "' 3

  • 8/13/2019 PRE201

    15/16

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

    /nline co''unities

    Nearl' the $randdadd' of them all, ompu%erve has opened their forums to the &e#(%tart at httpE&&&(compuserve(com, and $o from there( A direct lin+ that &or+s forme is httpE$o(compuserve(com"%5evApps?locUus- 'our milea$e ma' var'(

    Pro#a#l' the most active FoxPro communit' on the &e# toda' ishttpE&&&(universalthread(com, &ith man' &ell-+no&n authors and spea+ersfre=uentin$ the site( A close runner-up is the repositor' of +no&led$e #uilt up #' itsmem#ers at httpEfox(&i+is(com- a remar+a#le, or$anic site that allo&s visitors toadd, edit and enhance the existin$ &e# site( /ut there are a num#er of other&orth&hile sites( *od Paddoc+ hosts httpE&&&(foxforum(com( 0d Leafe hosts theProFox mailin$ listC 'ou can si$n up at httpE&&&(leafe(com, and the Virtual FoxPro:ser Kroup is online at httpE&&&(vfu$(or$(

    ooks

    Im a #i$ advocate of learnin$ #' readin$( )here are a lot of fascinatin$ #oo+s outthere, and I am al&a's in the process of readin$ a fe& at a time( If this isnt 'ourst'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 $roupmeetin$s, or &or+in$ &ith them(

    %teven /lac+ has an extensive readin$ list at httpE&&&(steven#lac+(com- loo+ for1#oo+shelf(2 Whil 7entDen maintains another list at httpE&&&(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

  • 8/13/2019 PRE201

    16/16

    ,inks

    &n e,cellent e,planation of t+e &CI0 principles is a1ailale on

    !ttp:""###$asdigita$com"books"panda"databases%c!oosing

    Lammers, %usan, Programmers at Work"icrosoft Press, 34, 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 H,...9

    dBASEis a re&istered trademar' o( dBASE Inc) Ot%er dBASE Inc) #rod*ct names are trademar'sor 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-%hareAli+e >(. :nited %tates License( )o vie& a cop' of this license, visithttpEcreativecommons(or$licenses#'-nc-sa>(.us or send a letter to reativeommons, 3G3 %econd %treet, %uite >.., %an Francisco, alifornia, 4B3.