>>>As vfp is basically prototypal, calling a function in the base class to set the property should only run once.
>>>Next classes of that base class just copy properties from first one and run defined methods.
>>>But you have put that code/call either in property window if vcx based or in the "declaration area" just after "define class" in prg based class - NOT in .init() or any other function of base class. Check by adding a log entry or wait window...
>>
>>You misread a bit - he intends to run some code to check for a global setting, during the instantiation of any label, and "base class" is of course not Label but MyBaseLabel. So the antediluvian question of OOP says "where does the code go?", and in this case MyBaseLabel.init() is the place.
>
>I think I interpreted his intentions correctly, even if the effect is less damaging as he fears.
>
>The MyBaseLabel.init() the code will run for EACH label put on any form, creating a minuscle time lag. But if this is done for dozens of properties for hundreds of labels, users will notice. The .Init() is NOT the place, only the inheritance level is correct, as this enhanced example of vfp help proves
>oDef = CREATEOBJECT("defaultgiver")
>frmMyForm = CREATEOBJECT("Form")
>frmMyForm.Width = 450
>frmMyForm.Height = 100
>frmMyForm.Caption = "Scope Resolution Example"
>frmMyForm.AutoCenter =.T.
>frmMyForm.AddObject("cmdQuit","cmdQuitButton")
>frmMyForm.AddObject("cmdAnother","cmdAnotherButton")
>frmMyForm.SHOW
>WAIT WINDOW oDef.nCount NOCLEAR NoWait
>READ EVENTS
>
>DEFINE CLASS defaultgiver as Custom
> defColor = RGB(127,0,0)
> nCount = 0
> PROCEDURE defColor_ACCESS()
> this.nCount = this.nCount + 1
> wait window "Called" + STR(this.nCount) TIMEOUT 1
> RETURN RGB(0,0,255)
>enddefine
>
>DEFINE CLASS cmdDumbButton AS CommandButton
> PROCEDURE init
> this.ForeColor = oDef.defcolor
>ENDDEFINE
>
>DEFINE CLASS cmdSmartButton AS CommandButton
> ForeColor = oDef.defcolor
>ENDDEFINE
>
>#if .f.
>DEFINE CLASS cmdQuitButton AS cmdSmartButton
>#else
>DEFINE CLASS cmdQuitButton AS cmdDumbButton
>#endif
>
> Caption = "\<Quit " + Proper(this.parentclass)
> Left = 95
> Top = 60
> Height = 25
> Width = 200
> Visible = .T.
> FontItalic = .T.
> PROCEDURE Click
> WAIT WINDOW "Executing the CLICK procedure for cmdQuit." TIMEOUT 1
> CLEAR EVENTS
>
>ENDDEFINE
>
>DEFINE CLASS cmdAnotherButton AS cmdQuitButton
> Caption = "Click "
> Top = 30
> PROCEDURE Click
> WAIT WINDOW "Click event for button: cmdAnotherButton" TIMEOUT 1
> cmdQuitButton::Click
>ENDDEFINE
>
>
>>Now what you say about "calling a function in the base class to set the property should only run once." is not what I observe while debugging. Simply because the code may not be generic, but may refer to this or this.parent or who knows which instance specific property. So it runs every time, for every instance's .init(). There were cases when I hated that (because I had to wait out dozens of controls' init()s to see what's up with a particular class of control which was misbehaving only in a very complicated form, on pgf2.page9), but there it is.
>
>The _Access Method is run only
once for ALL the smart buttons used inside the app, but EVERY time for EACH dumb button, which is caused by putting the code into .init() instead of setting the
property default for each user without involving the .init() of EVERY label.
>
>Just change the base class by editing the "#if .f." and compare the runs shown in wait window noclear.
>
>Or if you'd like more abstract definition, think of Javascript ALWAYS writing to the object instance, but reading up the inheritance tree until encountering the prototype level the property is first defined by writing to it. Setting the default value outside the init method is performing a caching of the "get personal default value for that property from data store" done in the init to write to the object instance on the prototype ONCE.
>
>regards
>
I am back to your code suggestion and have a question. Does it mean that the class "defaultgiver" has to be instantiated at the top of the application? So that all buttons (or whatever controls) use the property oDef.defcolor? And if my assumption is correct, the reference oDef has to be public, correct?
TIA
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham