Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Intellisense in WITH ... ENDWITH
Message
De
06/09/2012 15:31:40
Mike Yearwood
Toronto, Ontario, Canada
 
 
À
01/09/2012 15:47:20
Dragan Nedeljkovich (En ligne)
Now officially retired
Zrenjanin, Serbia
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01550535
Message ID:
01552507
Vues:
77
>>>I've found this extremely handy in the case where I needed to do a lot of snippets on a single scatter name object, without having to pass that object as a parameter to each, and there were more of a hundred of them, working on a few thousand records, so that would be an order of magnitude of 10K function calls. Specially neat, considering that this code may be called from a few different places, where I wouldn't know the name of the object in advance (so I couldn't use it as an inherited variable), and wanted to avoid passing a parameter (as that has its cost in a tight loop like this). Works like a charm, at the cost of writing a comment wherever this is called that it must be called within a with/endwith block.
>>>
>>>And the snippets look a lot nicer.
>>
>>I can't envision that. Give an example?
>
>The code called within the with/endwith block looks like this:
>
create cursor crserr (id i, cField c(60), objectid i, msg c(240))
>	if not Rule0201()
>		insert into crserr values (201, "dob", 20036, [date of birth cannot be blank.])
>	endif
>	if not Rule0202()
>		insert into crserr values (202, "age", 20034, [age out of range])
>	endif
>	if not Rule0203()
>		insert into crserr values (203, "priorcases ", 20068, [can't have prior cases if history is empty])
>	endif
>* about 80 more of these...
>select crs1cErr
>count to nErrCnt
>return nErrCnt
>
>PROCEDURE Rule0201
>Return  not empty(.dob)
>
>PROCEDURE Rule0202
>Return  empty(.age) or between(.age,15,65)
>
>PROCEDURE Rule0203
>Return  iif(.gotHistory=0, .priorCases=0,.t.)
>
>* other 80 such functions
>
>
>And this is the simple case, where most of these validation rules are one-liners. In other cases, the rules can get messy, field names long, and code rather complicated. Since all of these come from a single scatter name object, I could have used the alias instead (no assignments to fields happen in the code), but then this should be independent of the alias, as it's called from three contexts where any reasonably named alias may already be used for something else.
>
>The end of this is a simple
>
scatter name oSomething memo
>with oSomething
>   nErrorCount=myBigValidationFn()
>endwith
>which then works nicely even in a scan/end loop, and I don't even care who called it, from where, and what was the alias. And it's very fast.

Hi Dragan

I'd have created a memvar and passed it to the rules as a parameter. If each had the parameter from the start you would not have any gain from the with construct. What will you do if you needed nested WITH? It's a best practice to send parameters to a function to encapsulate it. This approach is not one that shows any advantage to WITH. :)

Mike
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform