In some cases, it is necessary for two clients to connect simultanously to a single Microsoft Jet OLE Database via ActiveX Data Objects (ADO). Normally, any changes introduced by a client are not immediately propagated to the other because of the buffering; this leaves a problem, if the programmer wishes the changes to be synchronized.
Microsoft describes how the issue can be resolved by using a library known as Jet And Replication Objects (JRO). Delphi's convenient set of wrappers for ADO does not include JRO; it can be imported, but using Microsoft's solution requires a simple trick, as described below:
Handling the JRE library
First, you will have to import the JRO type library. In the menu, select Project->Import Type Library, and in the list, pick up "Microsoft Jet and Replication Objects (version) Library". Push "Create Unit". In the source, usually called JRO_TLB.pas, amend the following line:
uses Windows, ActiveX, ADODB_TLB, Classes, Graphics, OleServer, StdVCL, Variants;
To:
uses Windows, ActiveX, ADODB_TLB, ADODB, Classes, Graphics, OleServer, StdVCL, Variants;
This makes Delphi identify the _Connection type in the new unit as the _Connection described in the Borland libraries (i.e. ADODB_TLB._Connection and ADODB._Connection, respectively). Build the unit and register the component.
Writing
Before each group of writes to the database, begin a transaction:
var Connection : TADOConnection;
{...} procedure WriteToDatabase; begin {...} Connection.BeginTrans; { Write to the database } Connection.CommitTrans; {...} end;
Reading
For reading you'll need to instanciate a JetEngine object:
uses {...} ADODB, JRO_TLB. { <-- Add the unit! } var JE: JetEngine; Connection: TADOConnection; begin JE = JetEngine.Create; { ... } end; procedure ReadFromDatabase; begin JE.RefreshCache(Connection.ConnectionObject); { ... } end;
As you can see, a single call will suffice. As covered elsewhere, you can also use the JetEngine object for compacting the database. To do just that, it is not even necessary to alter JRO_TLB.pas.