Board index » delphi » How to test a table is lock or not ???

How to test a table is lock or not ???

Hi my name is Ivan, I am studying delphi language.
I want to make a multiuser program using delphi table.
I want to know how to test a table is lock or not, so I can write a code
that loop and check the table is lock or not. The loop ended when the
table is unlock or not lock.
I know how to lock and unlock a table, but I don't know how to test a
table is lock or not.
Anybody can help me ??? :) Please let me know :)

Thank's a lot :
Ivan
Iva...@elang.stts.ac.id

 

Re:How to test a table is lock or not ???


Quote
Ivan Kurnia wrote in message <362EE3F1.7...@elang.stts.ac.id>...
>Hi my name is Ivan, I am studying delphi language.
>I want to make a multiuser program using delphi table.
>I want to know how to test a table is lock or not, so I can write a code
>that loop and check the table is lock or not. The loop ended when the
>table is unlock or not lock.
>I know how to lock and unlock a table, but I don't know how to test a
>table is lock or not.
>Anybody can help me ??? :) Please let me know :)

Check the CanModify property of the table:

if not Table1.CanModify then
  ShowMessage('Cannot edit this data');

--
Jeremy Collins
Kansai Business Systems

Re:How to test a table is lock or not ???


Quote
Ivan Kurnia wrote:
> I want to make a multiuser program using delphi table.
> I want to know how to test a table is lock or not, so I can write a code
> that loop and check the table is lock or not. The loop ended when the
> table is unlock or not lock.

You should consider that this solution doesn't guarantee neither mutual
exclusion nor bounded waiting. You have encountered what is called the
"critical section problem". Just refer to any book about operating
systems (e.g. Tanenbaum or Silberschatz/Galvin) to get a complete
description including a solution (Bakery-altogrithm).

Best regards,
Torsten
--
Torsten Binias                                             **     **  **
Student der Wirtschaftsinformatik an der                    ** * **   **
Westfaelischen Wilhelms-Universitaet Muenster                *****    **
WWW: "http://www.uni-muenster.de/WiWi/home/binias"            * *     **

Re:How to test a table is lock or not ???


Here is a procedure I use to test the locks on a table first. The
problem with Paradox tables is that a table lock will completely lock
you out of using the table, even in read-only mode. You just can't
open it at all. This is from the BDE help on Inprises site. Look for
their examples page. This procedure will fill a TStringList with lock
information about a table. You can then scan the list to test for any
type of lock.

procedure fDbiOpenLockList(Tbl: TTable; var LockList: TStringList);
var
  TmpCursor: hdbicur;
  Lock: LOCKDesc;
  rslt: dbiResult;
begin
 try
  Check(DbiOpenLockList(Tbl.handle, True, True, TmpCursor));
  Check(DbiSetToBegin(TmpCursor));
  LockList.Clear;
  repeat
    rslt:= DbiGetNextRecord(TmpCursor, dbiNOLOCK, @Lock, nil);
    if (rslt <> DBIERR_EOF) then begin
      LockList.Add('Lock Type: ' + IntToStr(Lock.iType));
      LockList.Add('User Name: ' + StrPas(Lock.szUserName));
      LockList.Add('Net Session: ' + IntToStr (Lock.iNetSession));

      LockList.Add('Session: ' + IntToStr (Lock.iSession));
      LockList.Add('Record Number: ' + IntToStr (Lock.iRecNum));
    end;
  until (rslt <> DBIERR_NONE);
  Check(DbiCloseCursor(TmpCursor));
  except
   on E: Exception do
     ShowMessage('Error obtaining list of table locks for
'+tbl.TableName+'.'+chr(10)+E.Message);
  end;
end;

Woody

Quote
Ivan Kurnia wrote in message <362EE3F1.7...@elang.stts.ac.id>...
>Hi my name is Ivan, I am studying delphi language.
>I want to make a multiuser program using delphi table.
>I want to know how to test a table is lock or not, so I can write a
code
>that loop and check the table is lock or not. The loop ended when the
>table is unlock or not lock.
>I know how to lock and unlock a table, but I don't know how to test a
>table is lock or not.
>Anybody can help me ??? :) Please let me know :)

>Thank's a lot :
>Ivan
>Iva...@elang.stts.ac.id

Re:How to test a table is lock or not ???


Quote
> Ivan Kurnia wrote in message <362EE3F1.7...@elang.stts.ac.id>...
> >Hi my name is Ivan, I am studying delphi language.
> >I want to make a multiuser program using delphi table.
> >I want to know how to test a table is lock or not, so I can write a
> code
> >that loop and check the table is lock or not. The loop ended when the
> >table is unlock or not lock.
> >I know how to lock and unlock a table, but I don't know how to test a
> >table is lock or not.
> >Anybody can help me ??? :) Please let me know :)

What you normally do, Ivan, is to try to lock the table yourself, and
then react if the attempt does not succeed.  Normally, locks are
attempted for a certain "retry interval," automatically by the system,
and you get an error if after that amount of time the lock could not be
obtained.

Other Threads