Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using a timer
Message
From
24/06/2016 20:16:14
 
 
To
24/06/2016 17:33:46
Luis Santos
Biglevel-Soluções Informáticas, Lda
Portugal
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 10
Network:
Windows Server 2012 R2
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01637566
Message ID:
01637693
Views:
83
>Hello Antonio
>
>thank you for the feedback, this example will surely help me.
>When you refer to isolate the query in a private session, I think it could create a procedure to trigger the timer and run my query instead of the message, right!?
>
>Once again thank you,
>Best regards
>Luis

Yes, but instead of running the query in the current data session, it would / should run it in a data session of its own. Since no one knows when the timed query is issued, if it is not ran isolated, it can mess with the data handling of the main application.

The concept is laid down in the next listing: while the user is manipulating data in a grid, a timer that is issued every 10 seconds performs data handling on its own without interfering with what is going on in the form, although it is the same data.
IF USED("curTestData")
	USE IN curTestData
ENDIF

IF FILE("curTestData.dbf")
	ERASE curTestData.dbf
	ERASE curTestData.fpt
ENDIF

CREATE TABLE curTestData (textColumn Varchar(20), numColumn I)

USE curTestData SHARED

INSERT INTO curTestData VALUES ("name", 1)
INSERT INTO curTestData VALUES ("other", 2)

GO TOP IN curTestData

LOCAL loForm AS aNormalDataHandlerForm

m.loForm = CREATEOBJECT("aNormalDataHandlerForm")
m.loForm.aGrid.RecordSource = "curTestData"
m.loForm.Show(1)

DEFINE CLASS aNormalDataHandlerForm AS Form

	ADD OBJECT aGrid AS Grid WITH AllowAddNew = .T.
	ADD OBJECT aTimer AS DataChecker

ENDDEFINE

DEFINE CLASS DataChecker AS Timer

	Interval = 0
	Checker = .NULL.
	
	PROCEDURE Init
		This.Checker = CREATEOBJECT("CheckData")
		IF !ISNULL(This.Checker)
			This.Interval = 10000
		ENDIF
		
		RETURN !ISNULL(This.Checker)
	ENDPROC
	
	PROCEDURE Timer
		This.Checker.Process()
	ENDPROC

ENDDEFINE

DEFINE CLASS CheckData AS Session

	DataSession = 2		&& private data session

	PROCEDURE Init
		USE curTestData SHARED
	ENDPROC
	
	PROCEDURE Destroy
		WAIT CLEAR
	ENDPROC

	PROCEDURE Process
	
		SELECT MAX(numColumn) AS maxColumn ;
			FROM curTestData ;
			INTO CURSOR curSummary
		
		SELECT curTestData
		GO BOTTOM
		
		WAIT WINDOW TRANSFORM(DATETIME()) + CHR(13) + ;
						"Records: " + TRANSFORM(RECCOUNT()) + CHR(13) + ;
						"Max number: " + TRANSFORM(curSummary.maxColumn) + CHR(13) + ;
						"Last text: " + textColumn ;
			NOWAIT NOCLEAR
	
	ENDPROC

ENDDEFINE
----------------------------------
António Tavares Lopes
Previous
Reply
Map
View

Click here to load this message in the networking platform