Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Design time event handler - part 2
Message
De
16/05/2007 12:27:35
 
 
À
16/05/2007 05:46:26
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
01225893
Message ID:
01226069
Vues:
14
>Hi all,
>
>the results I learned from the first discussion about a design time event handler hook are these:
>a) a projecthook would not work in case you don't use the project manager.
>b) it would be nice to have a DesignMode property being .T. when in design time and .F. if not
>c) Even if you hook into the event of modifying a class or form, that does not trigger an event, if you add subobjects in the designer.
>
>b) can be done more easy as I first thought, as Init() does not run in design mode, simply add that DesignMode property with default value .T. and in Init() set it .F.
>
>What I'm thinking now is have a permanent timer running, inspecting the array ASelObj() creates:
>
_Screen.AddObject("AselobjTimer1","AselobjTimer")
>
>Define Class AselobjTimer As Timer
>   Interval = 250
>   Procedure Init()
>      Clear
>      This.AddProperty("oDesignTimeIDs",Createobject("Collection"))
>   Endproc
>
>   Procedure Timer()
>      Private paObjects
>      Release paObjects
>      =Aselobj(paObjects,1)
>      Activate Screen
>      Local loObject, lnCount, llKeepID
>      With This.oDesignTimeIDs
>         For lnCount = .Count To 1 Step -1
>            llKeepID = .F.
>            If Type("paObjects",1)="A"
>               For Each loObject In paObjects
>                  If Pemstatus(loObject,"cDesignTimeID",5) And loObject.cDesignTimeID=.Item(lnCount)
>                     llKeepID = .T.
>                     Exit
>                  Endif
>               Endfor
>            Endif
>            If !llKeepID
>               ? "removed "+.Item(lnCount)
>               .Remove(lnCount)
>            Endif
>         Endfor
>
>         If Type("paObjects",1)="A"
>            For Each loObject In paObjects
>               If !Pemstatus(loObject,"cDesignTimeID",5) Or .GetKey(loObject.cDesignTimeID)=0
>                  AddProperty(loObject,"cDesignTimeID",Sys(2015))
>                  ? "added "+loObject.Name+ " as "+loObject.cDesignTimeID
>                  .Add(loObject.cDesignTimeID,loObject.cDesignTimeID)
>                  Try
>                     loObject.InitEventhandler()
>                  Catch
>                     ? "no eventhandler init found"
>                  Endtry
>               Endif
>            Endfor
>         Endif
>      Endwith
>   Endproc
>Enddefine
>
>This works in adding a cDesignTimeID property to any object and storing it in a collection. As long as the object lives it isn't touched again. If it's saved/closed, the item of the collection is removed by checking, if the ID is found in the array of living objects.
>
>You can now create whatever eventhandler by adding an Initeventhandler() method to your classes and forms, which is executed by this timer. Also put the Designmode property (default .T.) to it. In the init of your classes put...
>
>this.DesignMode=.F.
>this.InitEventhandler()
>
>...especially if you want the same eventhandling at runtime (also with handling events conditional on DesignMode property). Just don't try to bind to events or methods, if you want the eventhandler triggered at design time, as design time object methods like eg resize are not triggered, bind to height or width instead.
>
>Finally, because c) it would be nice to have some more hookclasses like the projecthook, some working at design time and others at runtime (too). This workaround by using a timer is not sufficient enough in other cases. It would even be better, if we could hook into certain commands being executed in general, like USE. (You can set breakpoints to used("somealias"), but that's bound to some alias and you can't even do that in runtime).
>
>Bye, Olaf.

Sums it all up nicely, I'd say Olaf. I'll have to try your timer class to see if it would be sufficient for me. Thanks for the efforts.
Fred
Microsoft Visual FoxPro MVP

foxcentral.net
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform