Other 3: Events

<< Click to Display Table of Contents >>

Navigation:  Examples > Other samples >

Other 3: Events

Previous pageReturn to chapter overviewNext page

This sample is designed to show you some of the recordset and connection events.

It implements two event handlers:

MyConnectionEvents

MyRecordSetEvents.

The only thing the methods of these event handlers do is to show that they are being called and to show their parameters like you can see below:

 

METHOD BeginTransComplete(lTransactionLevel , oError , lStatus , ;

 oConnection) CLASS MyConnectionEvents

 WriteLog( "BeginTrans", lTransactionLevel , lStatus , oConnection)

 

METHOD FieldChangeComplete (nFields , uFields , oError, lStatus, ;

 oRecordSet) CLASS MyRecordSetEvents

 WriteLog( "FieldChangeComplete", nFields , uFields , lStatus, oRecordSet)

 IF IsArray(uFields)

 AEval(uFields, {|oFld|WriteLog(" > Field", ;

 oFld:Name, OFld:Value, OFld:OriginalValue)})        

 ENDIF

 

The WriteLog() function write the results to the console and to a logfile.

The main program shows how to open a connection Asynchronous and Synchronous:

 

 oConn := AdoConnection{}

 AdoSetConnection(oConn)

 oConnEvents := MyConnectionEvents{}

 oConn:EnableEvents(oConnEvents)

 // Set the connection for better error reports

 WriteLog("ASynchronous open")

 AdoSetConnection(oConn)

 oConn:CursorLocation := adUseClient

 oConn:Open(strCnn,NIL,NIL,adAsyncConnect )

 DO WHILE oCOnn:State != adStateOPen

 WriteLog("Connecting...")

 Sleep(10)

 ENDDO

 oConn:Close()

 WriteLog("Now normal Synchronous open")

 oCOns:WriteLine("Enter to continue")

 oCOns:Read()

 oConn:Open(strCnn,NIL,NIL,NIL)

 

It also shows how to display the fetch progress of a recordset:

 

 oRstEvents := MyRecordSetEvents {}

 oRs:EnableEvents(oRstEvents)

 oRs:CursorLocation := AdUseClient

 oRs:Properties:[Item,"Initial Fetch Size"]:Value := 0

 oRs:Properties:[Item,"Background Fetch Size"]:Value := 5

 WriteLog("The recordset is opened. " )

 WriteLog("A fetchprogress will be called on ANOTHER THREAD for every 5 rows")

 oCons:WriteLine("Enter to continue")

 oCOns:Read()

 oRs:Open("employee",oConn,adOpenKeySet,AdLockOptimistic,adCmdTable+AdAsyncFetch)

 DO WHILE oRs:State != AdStateOpen .and. oRs:State <> AdStateClosed

 WriteLog("Fetching")

 Sleep(5)

 ENDDO

 

Please note that this will cause a second thread to be started. Be very careful with what you do in the second thread. Accessing GUI objects will certainly cause runtime errors, since the VO GUI classes are NOT threadsafe !