Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Design time event handler - part 2
Message
De
16/05/2007 16:06:13
 
 
À
16/05/2007 13:03:14
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
01225893
Message ID:
01226156
Vues:
16
> No matter what I try, I can't get my code in the class.InitEventhandler to execute.
Ouch, i get the same, should have tried with a little sample class. It seems not only events but all methods are disabled in design time objects. Like with the third parameter of the Newobject() function set to 0.

Well, then I can go back to my idea of EventhanlderClass/EventhandlerClasslib properties and let the timer create the event handler.

The timer now looks like this:
_Screen.AddObject("AselobjTimer1","AselobjTimer")

Define Class AselobjTimer As Timer
   Interval = 250
   Procedure Init()
      Clear
      This.AddProperty("oDesignTimeIDs",Createobject("Collection"))
      This.AddProperty("oEventhandlers",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
                     This.oEventhandlers.Add(NewObject(loObject.EventhandlerClass,;
                        loObject.EventhandlerClasslib,"",loObject))
                  Catch
                     ? "failed to create eventhandler"
                  Endtry
               Endif
            Endfor
         Endif
      Endwith
   Endproc
Enddefine
A simple eventhandler is:
Define Class Widthhandler As Custom

   Procedure Widthchange()
      Activate Screen
      ? "width changed"
   Endproc

   Procedure Init
      Lparameters toObject

      If toObject.DesignMode
         If PemStatus(toObject,"Width",5)
            BindEvent(toObject,"Width",This,"Widthchange")
         EndIf
      Else
         If PemStatus(toObject,"Resize",5)
            BindEvent(toObject,"Resize",This,"Widthchange")
         EndIf
      Endif
   Endproc
Enddefine
and the typical setup for a class usable with the timer and an eventhandler would be
Define Class xyz As Form
   EventhandlerClass = "Widthhandler"
   EventhandlerClasslib = "somepath/some.vcx or prg"
   DesignMode = .T.
   Name = "Form1"

   Procedure Init()
      This.DesignMode = .F.
      Try
         _Screen.Newobject(Sys(2015),This.eventhandlerclass,This.eventhandlerclasslib,"",This)
      Catch
         *
      Endtry
   Endproc
Enddefine
and this of course should be some visual class, not a prg class, as "MODI COMM" will not trigger anything.

Bye, Olaf.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform