When should i use SCATTER NAME ? and what is the benifit to scatter the record data to an object ? Because i still quite new to VFP, so please some body give me some advice. thanks
When should i use SCATTER NAME ? and what is the benifit to scatter the record data to an object ? Because i still quite new to VFP, so please some body give me some advice. thanks
SCATTER MEMVAR has been around since the early days of FPD (Foxpro DOS), and was use to copy a whole record (all the fields) with one line of code to memory variables, and using GATHER MEMVAR to append a record with the memory variables. And MS even decided to keep it around up until now and add the NAME paramter to make it OOP-like. It is usefull when you are copying and appending two tables of the same structure with one line of code (or 2), rather than using REPLACE.
Mike Gagnon
If you want to get the best response to a question, please check out FAQ184-2483 first.
>> When should i use SCATTER NAME ? and what is the benifit to scatter the record data to an object ? Because i still quite new to VFP, so please some body give me some advice. thanks <<
It is very handy when you need to pass a record around between various methods or other objects in the environment.
Hello Andreateh and welcome to the FoxPro community!
Here's my two cents worth...
You should NEVER use SCATTER MEMVAR. Always use SCATTER NAME for the following reason. If you SCATTER MEMVAR and you have any variables defined with the same name as one of the fields in the table you are SCATTERing from that variable will be overwritten with the value and type of the field in the table. These types of bugs can cause you a real headache when debugging an application.
Granted, you should be careful in naming your variables so that this does not happen but when more than one person is working on a project or if the project is large it is impractical to expect that you will remember every variable and field name in the system.
The biggest benefit is that you can contain your variables. Rather than having a bunch of memory variable that can write over each other when you issue scatter you contain it to a single object. Reference that object throughout your routine and the release it when you are done. It takes less memory and it is very clean.
A history behind scatter. It was designed in the early FoxPro days so we could scatter to memory, and then assign these memory variables to our forms. When the user pressed SAVE we issue a gather. If they pressed REVERT we reissued a scatter.
We can still do that on forms using the object (setting the object / property as the control source) but buffering is usually a preferred method.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.