Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SCATTER NAME.. What is the benefit ?

Status
Not open for further replies.

andreateh

Programmer
Jul 19, 2003
83
SG
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
 
andreateh said:
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.
 
Hello Andreateh.

>> 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.







Marcia G. Akins
 
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.

I hope this helps!

Steve
 
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.




Jim Osieczonek
Delta Business Group, LLC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top