Hi, I'm toying around with a projecthook, that hooks into the class designer (could also be the form or report designer) to handle design time events. To be more precise I bind to the objects of the modified class in the class designer like a builder does, but with bindevent binding to properties of that object to react to changes. Probable usage could be design time anchroing or creating a control with memberclasses the same way grids or pageframes etc. can handle them.
This is, what I got so far:
Cd f:\foxtests\projecthooks\widthhook\
Create Class widthhook of widthhook.vcx As projecthook nowait
=ASelObj(laClasses,1)
loProjectHookClass = laClasses(1)
loProjectHookClass.Writemethod("WidthChange","? 'width changed'",.t.,1)
Text To lcMethod Noshow
Set Classlib To (this.classlibrary) Additive
EndText
loProjectHookClass.Writemethod("Init",lcMethod)
Text To lcMethod Noshow
This.Addproperty("oTimer",CreateObject("WaitForObjectTimer",This))
EndText
loProjectHookClass.Writemethod("QueryModifyFile","Lparameters
oFile,cClassname"+Chr(13)+Chr(10)+lcMethod)
loProjectHookClass.Writemethod("QueryNewFile","Lparameters
cFileType"+Chr(13)+Chr(10)+lcMethod)
Keyboard '{CTRL+S}'
Keyboard '{Alt+F4}'
Keyboard 'Y'
Create Class WaitForObjectTimer of widthhook.vcx As Timer nowait
=ASelObj(laClasses,1)
loTimerClass = laClasses(1)
loTimerClass.interval = 100
Text To lcMethod Noshow
Lparameters toEventhandler
This.Addproperty("oEventhandler",toEventhandler)
EndText
loTimerClass.Writemethod("Init",lcMethod)
Text To lcMethod Noshow
Local Array laObject[1]
If ASelObj(laObject,1)>0
This.enabled = .f.
If PemStatus(laObject(1),"Width",5)
BindEvent(laObject(1),"Width",This.oEventhandler,"WidthChange")
EndIf
This.oEventhandler.oTimer = .null.
EndIf
EndText
loTimerClass.Writemethod("Timer",lcMethod)
Keyboard '{CTRL+S}'
Keyboard '{Alt+F4}'
Keyboard 'Y'
1. Save that code to a prg, run it once. This creates a classlib widthhook.vcx (change line 1 CD statement as you like).
2. Open a project or create one, in project info check "Project Class" and choose thw widthhook class from widthhook.vcx
3. Close and Reopen that project to activate the hook
4. Create or Modify anything with a Width property in the project manager. If you resize it "width change" will be printed on the _screen.
It would of course be better to have the eventhandler as a seperate class to be able to also bind to properties at runtime without having the projecthook overhead. Especially if you think about binding to a count property which like in the grid works both at design time and at runtime. What I dislike is the dirty trick to wait for AselObj() with a timer. At least there should be some exit code if something fails and Aselobj() never creates an array with a valid object reference.
I had this idea quite long ago in a tek-tips thread about how to do such things at design time, I think Mike Lewis said he made something like this with builders. Not quite interactive like this, but maybe worth to combine. Any pointers about a universal design time eventhandler like this?
Bye, Olaf.