>>>With asynchronous connections, you can do exactly that. I've got a search dialog that searches patients through an asynchronous query and displaying a animated GIF and at the same time being able to cancel out the search is perfectly possible and not even that difficult.
>
>Care to share the gist of it, after your earlier fabulous automagic connection preserver?! ;-)
My code involves a lot more than just the mechanism so I'll try to illustrate the neccesities. I've build it into a class with a timer part of it. So the following is from the top of my head and is not tested in any way.
First of all, you need a asynchronous connection
THIS.Handle = SQLSTRINGCONNECT(THIS.ConnString)
SQLSETPROP(THIS.handle, "Asynchronous", .T.)
THIS.TIMER = CREATEOBJECT("Timer")
THIS.TIMER.ENABLED = .F.
THIS.TIMER.INTERVAL = 100
BINDEVENT(THIS.TIMER, "Timer", THIS, "CheckResults")
Create a seperate method to execute the query
FUNCTION Start(cSql, cAlias)
THIS.Alias = cAlias
nRet=SQLEXEC(THIS.handle, cSQL, THIS.Alias)
THIS.TIMER.ENABLED = .T.
RETURN nRet
ENDFUNC
And do the checking in the CheckResults event (binded the timer.timer event)
FUNCTION CheckResults
IF SQLGETPROP(THIS.h,"ConnectBusy") = .F.
RAISEEVENT(THIS, "QueryEnd")
THIS.TIMER.ENABLED = .F.
ELSE
lRet= SQLEXEC(THIS.handle) > 0 AND USED(THIS.Alias)
IF lRet
THIS.TImer.Enabled = .F.
RAISEEVENT(THIS, "QueryEnd")
ENDIF
ENDIF
ENDFUNC
Now its important to mention this works not work so well in the following conditions
1. Queries that return a lot of data over slow connections. The reason for this is that the SQLEXEC in the checkresults event will not be return control to VFP until all the data has been downloaded to VFP.
2. Some queries will return the first few results very quickly, but it might take some time to get the full resultset. This usually is caused by large table or index scans that need a lot of filtering. There is a simple workarround for this by ordering the result (using ORDER BY) in some way (not matching the clustered index) which forces SQL server to first get all the results before sending back to the results to VFP.
You can use SQLCANCEL to cancel the query at any time. At a minimum do this at the destroy of the class.