Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

VFP 8 Feature Highlights

There are so many new features in VFP 8 that we can't cover them all. Claudio does his best to hit the high points in this round-up of several exciting new capabilities that VFP 8 brings to the table.


advertisement

isual FoxPro 8 includes numerous new features that are a direct response to the requests of VFP developers. Just reading through the "What's New" section of the documentation will take you quite a while due to large quantity of additional or changed features and commands. Not only does the documentation of new features in VFP 8 take up a large number of pages, but there are more than 100 new keywords added to the language. These represent additional Commands, Functions, Class names, Properties, and Methods.

You will have to explore VFP 8 on your own to discover many of the great new additions, but I will give you a quick tour of some of the new feature highlights that have caught my attention.

Insert-SQL Changes
The Insert-SQL command has gained two great new capabilities. It can now accept data that comes from an object or from a Select-SQL statement. For example, if you have an object (very likely a business object) that among its PEMs has properties that match fields in a cursor, you can insert data into the cursor right from the object. The syntax is very trivial:

   Insert into curProducts from name oProduct

Note that oProduct is the name of the business object that has the data. This feature lets you avoid the need to append a blank record to the cursor and then fill the fields with the gather command, as in:

   Append Blank in curProducts
   Gather from name oProduct

Here goes the other new feature: instead of having to get a result set from a query and scan through it populating a cursor, now you can do all at once:



   Insert into curProducts ;
    (ProductID, ProductName, UnitPrice);
      Select ProductID, ProductName, UnitPrice ;
         from Products Where UnitInStock > 20

An "Empty" Object?
For a long time, developers have been looking for a lightweight class, mainly when they have to add and remove properties to an object on the fly. Some people have been using the Session or the Custom classes, but those are not really intended to be lightweight classes. Others use classes like Relation or Line, but that is kind of weird from an OOP point of view, because a Relation class is meant to abstract relations between tables, while a Line class is meant to be a visual line in a UI control. The Empty class enters the picture.

The Empty class does not have any intrinsic properties, methods or events (yes, that's why it is called empty). Not having any members, this class gets instantiated and destroyed very quickly. Of course, this class is useless as is, because if it doesn't have an AddProperty method like all the base classes in VFP, how can we make any use of it?

The answer is two more new features: the AddProperty and RemoveProperty functions. Despite the fact that these functions can work with any object, their biggest role is to support the Empty class. The use of these functions and the Empty class is very trivial:

   oCustomer = CreateObject("Empty")
   AddProperty(oMonths, "LastName")
   AddProperty(oMonths, "FirstName")
   oCustomer.LastName = "Lassala"
   ? oCustomer.LastName

For removing a property, it goes like this:

   RemoveProperty(oMonths, "LastName")

Another use for the Empty class comes with using the Scatter command. The Scatter Name oObject command creates an object that has one property for each field in the cursor or table in the current work area, storing the values of the fields into the properties in the brand new object.

But, now we can create an Empty object beforehand, which has some additional properties besides the ones that match with the fields in the cursor, and then use the new ADDITIVE clause to the Scatter command, which will cause the use of an existing object, instead of a brand new one.

For example, if we still have in memory the oCustomer object for the previous sample, we can scatter fields from the customer table to it like this:

   Use Customer
   Scatter Name oCustomer Additive

An Empty class is a sealed class, which means that it cannot be sub-classed.



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date