Solved

Updating a Paradox record

Posted on 1998-11-11
13
288 Views
Last Modified: 2010-04-04
How can I prevent 2 users in a network to change the same Paradox record at the same time?
0
Comment
Question by:rainbowsoftware
  • 6
  • 2
  • 2
  • +2
13 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1346485
hi rainbowsoftware,

you can do this by using the bde-api
by using following functions


DbiGetRecord -> set a lock

DbiIsRecordLocked -> ask for current record is locked

DbiRelRecordLock -> Release a lock

for further Details see the BDE32.HLP File. There are Delphi and C++ examples in it.

meikl
0
 
LVL 2

Expert Comment

by:SupWang
ID: 1346486
Use Exclusive to prevent other applications from accessing a Paradox or dBASE table while this application is using it. Before opening the table, set Exclusive to True.
When Exclusive is True, then when the application successfully opens the table, no other application can access it. If the table for which the application has requested exclusive access is already in use by another application, an exception is raised. To handle such exceptions, write an exception handler.

Regards,
SupWang
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1346487
hi supwang,

your answer means that the table can only accessed by a single user. I mean that is not the solution, for what rainbowsoftware asked.

meikl
0
 

Author Comment

by:rainbowsoftware
ID: 1346488
Yes, what I want is to lock a record and not a table, so the hint from Kretzschmar is showing me in the right direction, but I am unable to find an example in the HLP-file.
Could you please give me an example?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1346489
hi rainbowsoftware,

here are the functionheaders, locktypes and a example from the helpfile to dbirgetrecord


LockTypes

dbiNOLOCK      No lock
dbiREADLOCK      Read lock
dbiWRITELOCK      Write lock


function DbiRelRecordLock (hCursor: hDBICur; bAll: Bool): DBIResult stdcall;

function DbiIsRecordLocked (hCursor: hDBICur; var bLocked: Bool): DBIResult stdcall;

function DbiGetRecord (hCursor: hDBICur; eLock: DBILockType; pRecBuff: Pointer; precProps: pRECProps): DBIResult stdcall;


procedure fDbiGetRecord(ATable: TTable; var RecID: Longint);
var
  CP: CurProps;
  RP: RecProps;
begin
  with ATable do begin
    // Make sure it is a Paradox table!
    UpdateCursorPos;                // sync BDE with Delphi
    // Find out if table support Seq nums or Physical Rec nums
    Check(DbiGetCursorProps(Handle, CP));
    Check(DbiGetRecord(Handle, dbiNOLOCK, nil, @RP));
    if  StrComp(CP.szTableType, szDBASE) = 0 then
      RecID := RP.iPhyRecNum

    else
      if  StrComp(CP.szTableType, szPARADOX) = 0 then
        RecID := RP.iSeqNum
      else
        // raise exception if it's not a Paradox or dBASE table
        raise EDatabaseError.Create('Not a Paradox or dBASE table');
  end;
end;

i hope its helpfull for you. to write a little example-application needs some time

meikl


0
 
LVL 1

Expert Comment

by:rpetruni
ID: 1346490
I don't know about Paradox tables, but with DBase all you have to do is to edit this record ;
Table1.Edit;
 (the record on wich you are will be locked until you release it (by posting, filtering etc.)
When a table is in Edit mode nobody else could change this record, so you really don't need to use anything else.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 27

Expert Comment

by:kretzschmar
ID: 1346491
hi  rainbowsoftware,

rpetruni has right, a writelock will be set on the current record by table.edit in paradox and dbase. I've verified it. Why complex solutions, when it's so easy.

Good Tip, rpetruni.

meikl
0
 

Expert Comment

by:elkiors
ID: 1346492
I agree, Paradox tables have auto-record locking. You can verify it easily, just create a simple app with a form containing a table grid. Now execute multiple instances of the app. As soon as the dsEdit mode becomes active, it is not possible for another instance to enter dsEdit mode. Moreover, you are automatically advised which user currently owns the record lock.
Have a play around with the multiple instances and the effects they have on one-another, I find that's the best way of seeing what's going on. The beauty of it is that it's really easy to set up a single table with an alias to act as a test bed.

Have fun

Darren
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1346493
Hello? Is somebody here?
0
 

Expert Comment

by:elkiors
ID: 1346494
I'm here but only because you posted, the message.

Darren

0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1346495
Hello, some other here except darren?
0
 

Author Comment

by:rainbowsoftware
ID: 1346496
I have tested my application on another netvork and rpetruni is right, the record is locked for another user upon edit.
So maybe it is the network that is errorneuasly configured, so the only thing, I want to know now, is how you english-talking people are spelling the damned word errorneausly.

0
 
LVL 1

Accepted Solution

by:
rpetruni earned 100 total points
ID: 1346497
Hi,
yes this really works fine, but you have to be carefool not to filter the table or things like that after Edit, because you will cancel it by dooing so (this was my problem at first, so i was looking for an answered answer few weaks, yust to found it back again).
So when i want to lock the record i Edit the table, then i do anything i have to. If i happend to use filter after Edit, or anything that cancel it i yust repet Edit command, and so on  until Post...

I'm not English talking man, and i eawen don't know what the word errorneuasly means, so ....

Do you want to say that on your network things don't work like they should?

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now