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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find out what overhead comes with a class?

Status
Not open for further replies.

Nifrabar

Programmer
Mar 16, 2003
1,343
NL
Hi,

Once I create a custom (e.g. parameter) object I am wondering what baseclass to use.
In 1001 things 'relation' is often used but I think that it's done because it was based upon VFP6.

Is there some docu which gives info about VFP9 on this topic?

-Bart
 
Hi Bart,

the Relation class is a nice lightweight class. the good thing is, it has AddProperty and ResetToDefault methods.

Even more lightweighted is the empty class. But it's not derivable, you can just create an empty object and have to add everything at runtime. You can use the AddProperty() function to add properties to it.

if you want to populate such an object with table fields, scatter name is still the way to go, even if you don't gather from that object later. Insert From Name and Scatter Name Additional are nice extensions of vfp9.

Here is some basic version of a function for creating parameter objects based on the empty class:

Code:
Local lo

? CreateParameterObject()

lo = CreateParameterObject("iX;iY")
? lo.iX, lo.iY

lo = CreateParameterObject("iX;iY","I;I")
? lo.iX, lo.iY

lo = CreateParameterObject("iX;iY","I;I","20;100")
? lo.iX, lo.iY

lo = CreateParameterObject("cFirstname;cLastname;dBirthdate","C;C;D","Olaf;Doschke;{^1968-12-28}")
? lo.cFirstname, lo.cLastname, lo.dBirthdate

lo = CreateParameterObject("iMembers;cType","I;E","AMembers(laDummy,loObject);Type('loObject.cType')")
? lo.iMembers, lo.cType

Function CreateParameterObject()
   Lparameters tcProperties, tcTypes, tcValues
   Local loObject
   loObject = Createobject("empty")

   Local lnCount, lnCounter
   Local Array laProperties[1], laTypes[1], laValues[1]
   Do Case
      Case Pcount() = 0
         loObject =.Null.
      Case Pcount() = 1
         * just add properties and leave them uninitialised
         For lnCount = 1 To Alines(laProperties,tcProperties,2,";")
            AddProperty(loObject,laProperties[lnCount])
         Endfor
      Case Pcount() = 2
         * add properties with default values in their variable type
         lnCounter = Alines(laProperties,tcProperties,2,";")
         If Alines(laTypes,tcTypes,0,";") # lnCounter
            loObject =.Null.
         Else
            For lnCount = 1 To lnCounter
               lcType = laTypes[lnCount]
               AddProperty(loObject;
                  ,laProperties[lnCount];
                  ,Icase(lcType="C","";
                        ,lcType="I",0;
                        ,lcType="N",0.0;
                        ,lcType="D",{};
                        ,lcType="Y",$0.0;
                        ,lcType="L",.F.;
                        ,lcType="T",{};
                        ,.Null.;
                        );
                  )
            Endfor
         Endif
      Case Pcount() = 3
         * add properties with passed in values in their variable type
         lnCounter = Alines(laProperties,tcProperties,2,";")
         If Alines(laTypes ,tcTypes ,0,";") # lnCounter Or;
               ALines(laValues,tcValues,0,";") # lnCounter
            loObject =.Null.
         Else
            For lnCount = 1 To lnCounter
               lcType  = laTypes[lnCount]
               lcValue = laValues[lnCount]
               AddProperty(loObject;
                  ,laProperties[lnCount];
                  ,Iif(lcType="C",lcValue,Evaluate(lcValue));
                  )
            Endfor
         Endif
   Endcase
   Return loObject
Endfunc

Bye, Olaf.
 

Bart,

I mainly use the Session class for this kind of thing. The main reason is that I don't have to worry about explicitly setting the data session. But I don't know if it's a good choice from the point of view of overhead.

One disadvantage of the Session class is that you can only subclass it in code, not in the visual designer.

I've also heard of people using the Line class, which is relatively light.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top