Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Feedback
Message
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
Miscellaneous
Thread ID:
00910724
Message ID:
00910757
Views:
19
VFP timers work in vfp .EXE COMs, not in vfp mtdll COMs. However, we just found a timer that DOES work in vfp mtdll COM servers:
1) go get this .ZIP file from here: 

http://download.com.com/3000-2401-889219.html?tag=lst-0-1

2) unzip the .EXE and regsvr32 the associated .DLL 

regsvr32.exe ccrpTmr.dll

3) Build the following code as a MTDLL:

DEFINE CLASS TimerTest AS CUSTOM OLEPUBLIC
     oTimerControl = .NULL.
     oTimerEventHandler = .NULL.

     PROCEDURE INIT
          ** Create the timer object
          THIS.oTimerControl = CREATEOBJECT( "ccrpTimers.ccrpTimer" )

          ** Create the event handler
          THIS.oTimerEventHandler = CREATEOBJECT( "TimerEventHandler" )

          ** Attach the eventhandler to the timer control
          EVENTHANDLER( THIS.oTimerControl, THIS.oTimerEventHandler )

          ** Set the timer properties
          ** As soon as your set enabled to .T., the timer will begin functioning
          ** Event type, 0 - one shot timer event, 1 - Periodic timer events
          THIS.oTimerControl.EventType = 1
          THIS.oTimerControl.INTERVAL = 1000
          THIS.oTimerControl.ENABLED = .T.
     ENDPROC
ENDDEFINE

** Replace the path in the IMPLEMENTS line with the path where you  installed ccrptmr.dll
DEFINE CLASS TimerEventHandler AS SESSION
     IMPLEMENTS __ccrpTimer IN "c:\ccrp\ccrptmr.dll"

     PROCEDURE __ccrpTimer_Timer( Milliseconds AS NUMBER ) AS VOID ;
               HELPSTRING "Event that fires whenever [Interval] milliseconds elapses."

          ** Your timer event code goes here

          IF !DIRECTORY( "c:\temp\" )
               MD c:\temp          ENDIF
          =STRTOFILE( "", "c:\temp\" + ALLTRIM( STR( SECONDS(), 12, 2 )) + ".txt" )
     ENDPROC
ENDDEFINE

4) Instantiate the class:

oCom = CREATEOBJECT( "TimerTest.TimerTest" )

That's it!  Your timer events will now function correctly in a VFP MTDLL.  

One final thing to remember.  Before you release the object
(in the case of above, oCom) you must set the enabled property
of the timer control to .F. like this:

oCom.oTimerControl.Enabled = .F.

Otherwise VFP will crash with a C00005 error.
>Claude - Thanks so much for posting that code. A few years back I had considered a server "write-back-to-client-event" using timer (and COMRETURNERROR) - but my understanding [then] was that a timer object could not be contained in an OLEPUBLIC COM.
>
>Is there a rule (or something) regarding timer being contained in a COM?
>Thanks (again)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform