Board index » delphi » Record locking - two instances of paradox.db in different TTable components not locking

Record locking - two instances of paradox.db in different TTable components not locking

I have two instances of a paradox.db in different TTable components.

e.g and order table orders.db is linked to the items.db table on one form
using TTable and TDatasource components.

On another form which can be opened simultaneously is displayed a seperate
instance of items.db using another TTable component.

So one form displays orders and the items that belong to it in order no
sequence and on the other form displays all items of all orders in order of
item no.

The problem is if I navigate to a particular order and put one of the items
on the order in edit mode, then at the same time edit the corresponding item
on the other form I do not receive the record locked message.

However, if after I navigate to the order, I press the refresh button for
the item table then put the item in edit mode, and now edit the
corresponding item on the other form I do get the record locked message.

Help,

I thought I had{*word*180}ed most of my record lock problems, but this one is a
bit hard to fathom.

What could I be doing wrong, or missunderstood ?

Thanks in advance,

Leon SInagra

 

Re:Record locking - two instances of paradox.db in different TTable components not locking


Quote
>>However, if after I navigate to the order, I press the refresh button for
>>the item table then put the item in edit mode, and now edit the
>>corresponding item on the other form I do get the record locked message.

Try doing a TTable.Refresh from within the OnActivate event for the Form (I'm assuming that
you're using MDI).

=Bill=

Re:Record locking - two instances of paradox.db in different TTable components not locking


Quote
>The problem is if I navigate to a particular order and put one of the items
>on the order in edit mode, then at the same time edit the corresponding item
>on the other form I do not receive the record locked message.

>However, if after I navigate to the order, I press the refresh button for
>the item table then put the item in edit mode, and now edit the
>corresponding item on the other form I do get the record locked message.

>Help,

>I thought I had{*word*180}ed most of my record lock problems, but this one is a
>bit hard to fathom.

You can't have the same record locked in two places.  The simple solution is to
have both forms use the same Ttable.

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:Record locking - two instances of paradox.db in different TTable components not locking


On Sun, 22 Nov 1998 22:44:51 +0800, "Leon Sinagra"

Quote
<sina...@nettrek.com.au> wrote:
>I have two instances of a paradox.db in different TTable components.

>e.g and order table orders.db is linked to the items.db table on one form
>using TTable and TDatasource components.

>On another form which can be opened simultaneously is displayed a seperate
>instance of items.db using another TTable component.

>So one form displays orders and the items that belong to it in order no
>sequence and on the other form displays all items of all orders in order of
>item no.

>The problem is if I navigate to a particular order and put one of the items
>on the order in edit mode, then at the same time edit the corresponding item
>on the other form I do not receive the record locked message.

>However, if after I navigate to the order, I press the refresh button for
>the item table then put the item in edit mode, and now edit the
>corresponding item on the other form I do get the record locked message.

Leon,

I don't know *exactly* why you are not getting any error in the first
case.  But maybe you can explain it after you read this message.

It seems to me that opening different TTables in the same session will
just create multiple cursors on the *same* open physical table in the
BDE.  Consequently, the record locking mechanism on the two TTables
will just work as being on one table.

Normally, if you try to lock the same record in the same session you
get a DBIERR_ALREADYLOCKED error (translated to some exception in
Delphi like 'Record already locked in this session').  Now consider
the following sequence of events:
Table1.Open
Table1.Edit
Table2.Open
Table2.Edit  -> Exception: this is the expected behavior
Table2.Close (Delphi unlocks the record locked by Table1!)
Table2.Open
Table2.Edit  -> no exception anymore!!!

You see what happens?  While it is not possible to lock the same
record from two TTables in the same session, it *is* possible to
unlock a record that was originally locked from a different session,
just by closing a table.

I submitted a bug report about this more than 1.5 year ago (still
Delphi 2 and BDE 3.5 back then) but I got never an answer.  Apparently
Inprise thinks that we are using the product the wrong way.  IMO there
are two bugs involved though:
- a TTable should not release a record lock that it hasn't placed in
the first place
- the BDE should not allow to release a lock from a different cursor,
even if internally it is operating on the same file

If you think your application is suffering from the same bug, there
are two options:
- make different TSession and TDatabase components to open the table
the second time
- use my workaround (overriding the TTable component):

procedure TAdmTable.DestroyHandle;
begin
  // Bug in BDE and Delphi: Delpi releases the record lock on the
  // current record.  If the record is locked on another table object
  // in the same session, that lock is released.  We avoid this by
  // placing the cursor at EOF.
  if State <> dsEdit then
    DbiSetToEnd(Handle);
  inherited;
end;

HTH

Jan

Other Threads