There are, in the given example, two controls involved. One is the form, the other is the behavior control that is based on a customclass.
The form has a property oFormBehavior that is, initially, set to .null.
Another property is the cFormbehavior which is a comma delimited list containing the names of behaviorclasses.
The load of the form looks like this:
WITH THIS
.LoadDataBehavior()
.LoadFormBehavior()
.LoadMouseBehavior()
ENDWITH
At this place the formbehavior classes are loaded. That method looks like this.
LOCAL lcSaveBehavior, lcBehavior, loBehavior, lnI
*
* Save the behavior property
*
lcSaveBehavior = ThisForm.cFormBehavior
*
* Create the hook property
*
Thisform.AddProperty('oFormBehavior', NULL)
*
* Load the linked list of FormBehavior objects.
*
DO WHILE !EMPTY(ThisForm.cFormBehavior)
* Loop through all behaviors
*
ThisForm.cFormBehavior = CHRTRAN(ThisForm.cFormBehavior, ' ', '')
lnI = AT( ',', ThisForm.cFormBehavior)
IF lnI = 0
* The last behavior
*
lcBehavior = ThisForm.cFormBehavior
ThisForm.cFormBehavior = ''
ELSE
* More to come
*
lcBehavior = SUBSTR(ThisForm.cFormBehavior, 1, lnI - 1)
ThisForm.cFormBehavior = STUFF(SUBSTR(ThisForm.cFormBehavior, lnI), 1, 1, '')
ENDIF
IF NOT EMPTY(lcBehavior)
* A behavior class found, load it
*
loBehavior = CreateObject(lcBehavior, ThisForm)
IF ISNULL(ThisForm.oFormBehavior)
IF TYPE('loBehavior') = 'O' AND !ISNULL(loBehavior)
* The first behavior
*
ThisForm.oFormBehavior = loBehavior
ENDIF
ELSE
* Add it to the end of the list
*
ThisForm.oFormBehavior.AddBehavior(ThisForm, loBehavior)
ENDIF
ENDIF
ENDDO
* Make sure there is at least one object.
*
IF ISNULL(ThisForm.oFormBehavior)
ThisForm.oFormBehavior = CreateObject('BaseFormBehavior', ThisForm)
* by passing a reference from the form to the object to be created that ref comes in the init of that object...
ENDIF
ThisForm.cFormBehavior = lcSaveBehavior
This approach gives you the possibilities to add any behavior to forms, the only thing you have to do is add the classname to the list.
Now, among other things you will find, in the init of the form a line like this:
llReturn = ThisForm.oFormBehavior.FormInit(ThisForm)
As you can see the form passes itself to the forminit of the behaviorclass, which looks like this:
VFP>
* forminit method of a behaviorclass.
LPARAMETERS toForm
#INCLUDE Include\AppInc.h
WITH toForm
* Save the original size
*
THIS.nOldWidth = .Width
THIS.nOldHeight = .Height
* Set the maximum size
*
.MaxHeight = .Height * 1.25
.MaxWidth = .Width * 1.25
* Set the minimum size
*
.MinHeight = .Height / 1.25
.MinWidth = .Width / 1.25
* Enable the maximize button and set the form border
*
.maxbutton = TRUE
.BorderStyle = BORDER_SYSTEM && 3
ENDWITH
I had to tweak the code a bit for showing it on the forum.
If you have any Q's ask them!
For more info on this technique see my articles on "Hooked on objects" in the article section of foxite.
Boudewijn Lutge®ink
Boudewijn.Lutgerink@foxite.com"Unless something happens that we can't predict, I don't think a lot will happen."