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 : Page 2

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

Putting Some New Features Together
A practical use for an Empty object is getting rid of some of those public variables (or private variables in the main program) that some developers have spread through their applications, especially when they're not willing to move to an entirely OOP approach.

For example, usually some developers have a few public variables that store environment information, like the name of the Machine, the OS version, the user's name, and so on. This is a simple sample of how they could get rid of a few of those variables by using an Empty object:

   Private poApp
   *-- We create an "empty" object.
   poApp = CreateObject("Empty")
   *-- We add a few properties to the object.
   AddProperty(poApp, "MachineName",;      
               Substr(Sys(0),1,At("#",Sys(0))-1))
   AddProperty(poApp, "OSVersion", Os(1))
   AddProperty(poApp, "UserName",;
               Substr(Sys(0),At("#",Sys(0))+1))
You can see that we create just a single property that will store a reference to an Empty object, and then we use the new AddProperty function to add a few properties to the object (MachineName, OSVersion and UserName). We are using the AddProperty function to also initialize the values of the properties, but we could assign values to the properties in an Object.Property approach, like:

   poApp.OSVersion = Os(1)
Then, you can use this object anywhere:



   MessageBox("User Name: "+poApp.UserName+Chr(13)+;
      "Machine Name: "+poApp.MachineName+Chr(13)+;
      "OS Version: "+poApp.OSVersion)
Let's now see a sample that plays with the new features both in the Insert-SQL and the Scatter commands. Often, we need to keep track of the size and location of forms as they were the last time they were destroyed (the user runs a form, changes its size and location, then closes the form). The next time the user runs the form, he expects that it will be shown the same way. Doing that now is a piece of cake. Basically, we need a simple table that has numeric fields for keeping the size of a form and its position (Top, Left, Width, and Height). In the Destroy event method of the form, we put this line of code:

   Insert into Settings from name Thisform
Of course, we need to apply some logic to check whether we already have a record in the table keeping track of these values. If that's the case, we can just update the record with this line of code:

   Gather name Thisform
Both lines of code will take the Thisform reference to the form object, and then grab the value of its Top, Left, Width and Height properties to replace in the table.

Now, in the Init event method, we grab the values stored in the table and then update our object properties with this line of code:

   Scatter name Thisform additive
DataEnvironment Class and Builder
Let's picture a common situation: you have a form with a beautiful (read "complex") DataEnvironment defined, with lots of tables, relations, ordering, and so forth. Then you face a new need where you'll have another form that requires the same settings of the first one. Until VFP 7, you had two choices: recreate everything again from scratch manually or create the DataEnvironment programmatically. That was because we weren't able to define and subclass the DataEnvironment class. Now we are!

Now, with VFP 8, we can just go to the form that has the DataEnvironment defined, and then select Save As Class from the File menu. In the dialog box you'll find a new "DataEnvironment" option. Then, it's just a matter of typing the name of the class, where it should be stored and a description for it (see Figure 1)



Comment and Contribute

 

 

 

 

 


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

 

 

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