Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Cursor problem
Message
De
07/04/2006 07:30:05
Mike Yearwood
Toronto, Ontario, Canada
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Problèmes
Titre:
Divers
Thread ID:
01111196
Message ID:
01111320
Vues:
21
WITH ... ENDWITH can be dangerous.
WITH oCA
  .DataSource = oApp.GetSQLConnect()
ENDWITH

oApp.GetSQLConnect
*Through some recoding developer left this.
with oApp.something.somethingelse
  .blah1
endwith
.blah2
The .blah2 is now referring to oCA. That can be very hard to debug.

Since oCA is already a memory variable there is little benefit to using WITH...ENDWITH. Performance has to be balanced against safety and readability.

I believe this makes code more obvious, saves typing and more importantly reduces risks of simple programmer human error causing problems. It also improves the readability when multiple objects properties and methods are accessed in a single method.
oCA.DataSource = oApp.GetSQLConnect()

oApp.GetSQLConnect
*Through some recoding developer left this.

oST = oApp.something.somethingelse
oST.blah1
oST.blah2
>Naomi is right, remove all "this" from TEXT ENDTEXT.
>
>
>oCA = CREATEOBJECT([CursorAdapter])
>WITH oCa
>     .DataSourceType = [ODBC]
>     .DataSource     = sqlstringconnect([dsn=sqlfoxpro;uid=sql;pwd=sql])
>     .WhereType      = 1 && Key field only
>     .KeyFieldList   = [ident]
>     .Tables         = [dovendor]
>
>     TEXT TO .CursorSchema NOSHOW  PRETEXT 15 TEXTMERGE
>          CNTR_ORIG C(3), COMPANY C(35), CONTACT C(30), CR_BY C(10), CR_DATE T, EDI C(12), EMAIL C(40), FAX C(15),
>          IDENT I, LANGUE C(1), MAINADDR1 C(30), MAINADDR2 C(30), MAINCITY C(25), MAINCNTRY C(3), MAINSTATE C(3),
>          MAINZIP C(10), NOTE M, PHONE C(15), PLACE_EXP C(3), TAXID C(15), TITRE C(20), VENDNO C(10), VFDCODE C(3),
>          WEBPAGE C(100)
>     ENDTEXT
>
>     TEXT TO .SelectCmd NOSHOW  PRETEXT 15 TEXTMERGE
>        select cntr_orig, company, contact, cr_by, cr_date, edi, email, fax, ident, langue, mainaddr1, mainaddr2, maincity,
>               maincntry, mainstate, mainzip, note, phone, place_exp, taxid, titre, vendno, vfdcode, webpage
>        from dovendor
>     ENDTEXT
>
>     TEXT TO .UpdatableFieldList NOSHOW  PRETEXT 15 TEXTMERGE
>          cntr_orig, company, contact, cr_by, cr_date, edi, email, fax, ident, langue, mainaddr1, mainaddr2,
>          maincity, maincntry, mainstate, mainzip, note, phone, place_exp, taxid, titre, vendno, vfdcode, webpage
>     ENDTEXT
>
>     TEXT TO .UpdateNameList NOSHOW  PRETEXT 15 TEXTMERGE
>          cntr_orig dovendor.cntr_orig,
>          company dovendor.company,
>          contact dovendor.contact,
>          cr_by dovendor.cr_by,
>          cr_date dovendor.cr_date,
>          edi dovendor.edi,
>          email dovendor.email,
>          fax dovendor.fax,
>          langue dovendor.langue,
>          mainaddr1 dovendor.mainaddr1,
>          mainaddr2 dovendor.mainaddr2,
>          maincity dovendor.maincity,
>          maincntry dovendor.maincntry,
>          mainstate dovendor.mainstate,
>          mainzip dovendor.mainzip,
>          [note] dovendor.note,
>          phone dovendor.phone,
>          place_exp dovendor.place_exp,
>          taxid dovendor.taxid,
>          titre dovendor.titre,
>          vendno dovendor.vendno,
>          vfdcode dovendor.vfdcode,
>          webpage dovendor.webpage
>     ENDTEXT
>
>     .UseCursorSchema = .t.
>     .Alias           = [MyVFPRecorSet]
>ENDWITH
>
>IF NOT oCA.CursorFill()
>   AERROR(lAerror)
>   MessageBox([Can not fill the cursor adapter ]+lAerror[1,2])
>   RETURN
>ENDIF
>
>SELECT MyVFPRecorSet
>browse
>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform