Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to create an object in a class
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
01092108
Message ID:
01092694
Vues:
21
Zakaria,

Here's another example of the code. Run it and you'll see both objects have an age of 100 because of how the code sets the dBirthdate. But the both have different values for their associated oTime object and the object lifespan is output by the method I added.
oPerson1 = createobject( "Person" )
oPerson1.dBirthDate = datetime() - 100
? oPerson1.GetAge(), oPerson1.oTime.PointOfTime

messagebox( "delaying between the two people" )

oPerson2 = createobject( "Person" )
oPerson2.dBirthDate = datetime() - 100
? oPerson2.GetAge(), oPerson2.oTime.PointOfTime

messagebox( "letting the objects age" )

? oPerson1.ObjectAge(), oPerson2.ObjectAge()

DEFINE CLASS Person as Custom

cName = ""
dBirthdate = {//}
oTime = null
nAge = 0

function Init()
this.oTime = createobject("zaTime")
return dodefault()

function Destroy()
this.oTime = .null.
return dodefault()

FUNCTION GetAge()
RETURN  this.oTime.PointOfTime - this.dBirthDate
ENDFUNC

function ObjectAge()
return datetime() - this.oTime.PointOfTime
ENDDEFINE


DEFINE CLASS zaTime as Custom
PointOfTime = {//::}

function Init()
this.PointOfTime = DATETIME()
return dodefault()

ENDDEFINE
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform