Member Classes Bring Flexibility

Member Classes Bring Flexibility

eed to define several pages in a PageFrame with different properties and settings? No problem. How about better control of grid column headers? No problem. By changing the way you can define and work with member classes, Microsoft has given VFP developers tremendous flexibility in working with PageFrames and grids.

In Visual FoxPro, there are certain classes that have meaning only when they’re in containers: for example, Pages and Headers can live only in PageFrame and Column objects. In versions before VFP 8, if we wanted to subclass these classes, we needed to manually add them using the AddObject method. But, there were problems with this approach. For example, this kept us from putting controls on a subclassed page in the Form Designer.

However, VFP8 adds the MemberClass and MemberClassLibrary properties, as well as the HeaderClass and HeaderClassLibrary properties for the Column object. This lets us tell the containers what kind of controls they should be using when we change the properties that tell how many controls they contain. For example:

   *!* Create Header class library   TEXT TO lcMembHeader NOSHOW       DEFINE CLASS hdrMembClass as Header         cSort = "ASCENDING"         PROCEDURE DblClick            IF This.cSort = "ASCENDING"               This.cSort = "DESCENDING"            ELSE               This.cSort = "ASCENDING"            ENDIF            MESSAGEBOX(This.cSort)         ENDPROC       ENDDEFINE    ENDTEXT       *!* Create Column class library, and pull    *!* from Header class library   TEXT TO lcMembColumn NOSHOW       DEFINE CLASS colMembClass AS Column         HeaderClass = "hdrMembClass"         HeaderClassLibrary = "membHeader.prg"      ENDDEFINE    ENDTEXT       *!* Create Grid class library, and pull    *!* from Column class library   TEXT TO lcMembGrid NOSHOW       DEFINE CLASS grdMembClass as Grid         MemberClass = "colMembClass"         MemberClassLibrary = "membColumn.prg"      ENDDEFINE    ENDTEXT       *!* Write the libraries to disk   STRTOFILE(lcMembHeader, "membHeader.prg")   STRTOFILE(lcMembColumn, "membColumn.prg")   STRTOFILE(lcMembGrid, "membGrid.prg")   USE HOME(1) + "labels"   loform = CREATEOBJECT("Form")   loForm.NewObject("Grid1", "grdMembClass",       "membGrid.prg")   WITH loForm.Grid1      .RecordSource = "labels"      .RecordSourceType = 1      .Visible = .t.   ENDWITH    loForm.Show(1)

With every release of VFP, there is something added that’s so obvious, it tends to go in everyone’s defaults. With VFP3, it was Label.AutoSize = .T. VFP5 added ComboBox.BoundTo = .T. Now that we’re up to version 8, I think we’ll see something like the following:

   DEFINE CLASS pagRefresh as Page      lRefresh = .T.      PROCEDURE Activate         IF This.lRefresh            This.Refresh()         ENDIF       ENDPROC   ENDDEFINE

I added an lRefresh property to this class because of the possibility that you might not want a given page to refresh as soon as you switch to it.

Once you’ve defined the classes, you can use them in the Form Designer by setting the properties at design time. When you make a design-time change to the MemberClass property, all of the controls will use the same class, even those already defined at that point.

However, if you change the MemberClass and MemberClassLibrary properties at runtime, this will not affect existing controls.? This opens up some interesting possibilities for dynamically switching between MemberClasses as you instantiate various objects at runtime.

Listing 1 contains code to first change the MemberClass and MemberClassLibrary properties on a PageFrame in (simulated) design mode, then shows that at runtime the properties can be changed with just the new?Pages being instantiated with the newly-defined MemberClass.

For?a more detailed?example, please see the “Member Classes” Solution Sample that ships with VFP8. The easiest way?to?do this is to use the “Solution Samples” pane in the Task Pane, but you can still run SOLUTION.APP as always to get to the samples.

Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as