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:
01092655
Vues:
12
Zakaria,

The changes I made to the code will work in all versions of VFP.

Each zaTime instance will get the current time when it's instantiated by making the call to datetime() in its Init() method.

Each Person object will instantiate its own oTime object. The Person class code does need a change to add a this. reference:
FUNCTION GetAge()
RETURN this.oTime.PointOfTime - this.dBirthDate
ENDFUNC
The dodefault() call passes the methods call onto whatever code you might be inheriting from. In this particular case it's not needed because you were derived directly from a VFP BaseClass. But if Person was derived from some class say "Entity" and it has code in its Init() method it wouldn't be executed without the dodefault(). It's a good habit to get into to typically call dodefault() before or after your subclass' code. Sometimes it's necessary to structure the code:
... code that needs executing before the ParentClass code
dodefault()
... code that needs executing after the ParentClass code
You also have to consider that even though the ParentClass might not have code in a method right now, it may in the future so your subclass needs to accomodate it.

>It works as you have explained only the zaTime doesn't get instantiated because I'm using foxpro 9.
>
>I was wondering what is the use of dodefault(), what does it do?
>
>Furthermore, what I want to do is to pass the Time object to the Person object (it's just a fictive example). Is the following the way to do this,or are there any better methods:
>
>oPerson = createobject("Person")
>oTime = createobject("zaTime")
>oPerson.Init(oTime)
>oPerson.GetAge()
>
>*** the Function init is then as follow:
>function Init(toTime)
>this.oTime = toTime
>return dodefault()
>
>
df (was a 10 time MVP)

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

Click here to load this message in the networking platform