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:



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)})        



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{}


 oConnEvents := MyConnectionEvents{}


 // Set the connection for better error reports

 WriteLog("ASynchronous open")


 oConn:CursorLocation := adUseClient

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

 DO WHILE oCOnn:State != adStateOPen





 WriteLog("Now normal Synchronous open")

 oCOns:WriteLine("Enter to continue")




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


 oRstEvents := MyRecordSetEvents {}


 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")



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





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 !