Workaround to recordlevel locking with DELPHI5 using ACCESS2000 (Borland claims it cannot be done)

I HAVE FOUND A WORKAROUND TO RECORD LEVEL LOCKING WITH DELPHI5
Actually it is impossible to get Record Level Locking with Delphi 5 because
the Delphi ADO component's Pessimistic lock doesn't work. It is a know bug
(Basic Functionality Failure) reported in the DevSupport at Inprise. There
is no way around. OR SO THEY SAY. I found one.

You have to own a Microsoft Visual Studio 6 product, Professional or
Enterprise, to have to Microsoft ADO Data Control 6.0. Then you can use it
with Delphi as an ACTIVEX. After that, you only have to do what Microsoft
describes... and presto!!!! The Lock is working. Ofcource, since I don't
want to build all my Delphi 5 project around a Microsoft ActiveX Control, I
use just use it's ability of record locking on a fake table and with a
function i create I can see witch record is used just by trying to lock a
record at the fake table with the same id. If more than one table is needed
for lock then I just add the tablename to the id and I have a unique id I
can use to emulate record level locking on all my tables. Further more, the
technik works perfectly. By default the updates or the inserts on a table
will be canceled by the ActiveX if the power fails, so there is no  chance a
lock will remain, unless I use the Update method, which ofcource I dont....
Here is an example of code I have writen. ADODC1 and 2 are the wrappers for
the Microsoft ADO Data Control 6.0

NOTE: You can do the same without the ACTIVEX wrapper, just with OLEObject
creation using the MSAdodcLib_TLB import library, but then more code is
required for initialization and  stuff. If you own VB or VC or VJ this is
much quicker and reliable.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Db, ADODB, OleCtrls, MSAdodcLib_TLB;

type

  TForm1 = class(TForm)
    Adodc1: TAdodc;
    Button2: TButton;
    Adodc2: TAdodc;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Button6: TButton;
    Button7: TButton;
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Adodc1MoveComplete(Sender: TObject; adReason: TOleEnum;
      const pError: Error; out adStatus: TOleEnum;
      const pRecordset: _Recordset);
    procedure Adodc2MoveComplete(Sender: TObject; adReason: TOleEnum;
      const pError: Error; out adStatus: TOleEnum;
      const pRecordset: _Recordset);
    procedure Button4Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button2Click(Sender: TObject);
begin
  adodc1.refresh;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
  adodc2.refresh;
end;

procedure TForm1.Adodc1MoveComplete(Sender: TObject; adReason: TOleEnum;
  const pError: Error; out adStatus: TOleEnum;
  const pRecordset: _Recordset);
begin
  label1.Caption:=inttostr(adodc1.Recordset.AbsolutePosition);
end;

procedure TForm1.Adodc2MoveComplete(Sender: TObject; adReason: TOleEnum;
  const pError: Error; out adStatus: TOleEnum;
  const pRecordset: _Recordset);
begin
  label2.Caption:=inttostr(adodc2.Recordset.AbsolutePosition);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  Try
    adodc1.Recordset.Fields['Perigrafh'].Set_Value('DOKIMH1');
  except
    showmessage('Record is locked');
  end;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
  try
    adodc2.Recordset.Fields['Perigrafh'].Set_Value('DOKIMH2');
  except
    showmessage('Record is locked');
  end;
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
  adodc1.Recordset.CancelUpdate;
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
  adodc2.Recordset.CancelUpdate;
end;

end.