Board index » delphi » Looking the best method to get the user who locks a record

Looking the best method to get the user who locks a record

I am looking for the best method to get the user who locks a record.

I want to show a message such as 'the record is currently locked by user X'
instead of 'the record is currently locked by another user'

There is many way to do this such as :
- creating a user table and updating when editing other tables -> but it is
difficult to absolutly identify a particular record with complex keys
- create a semaphor

I tried to use the informations provided by the bde but I found nothing
(DbiGetUserList, DbiGetErrorContext, etc..)
I also look in www.dejanews.com but found nothing over 100 messages !

So if someone knowes the right way to do this I am very interested !

Alex

 

Re:Looking the best method to get the user who locks a record


Quote
>Alex

Delphi's default exception message on record locking, at least with D2 and
D4sp2 in the test I ran on record locking,  provides information that the
record is locked, the table involved and the user name of the user who has
locked the record.

I don't know if you are not getting all that information or if you don't
like the way in which it is presented.

If you want to query the BDE yourself you can use DbiGetErrorContext.

Please Note: That this example doesn't query the BDE to see which
eDatabaseError occured, the assumption for this example is that we have a
failed lock attempt.

procedure TForm1.Button1Click(Sender: TObject);
begin
  try
   table1.edit;
  except
   on edatabaseerror do
        ShowErrorUser(ecUserName);
 end;
end;

procedure tform1.ShowErrorUser(eContext: Integer);
var
  username: string;
begin
  setLength(username, dbimaxmsglen);
  dbigeterrorcontext(eContext, pchar(username));
  setlength(username, strlen(pchar(username)));
  if (username > '') then
    showmessage(format('Record Locked By:   %s',[username]));
end;

Wes

Other Threads