Solved

Updating a Paradox record

Posted on 1998-11-11
13
290 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

914 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

22 Experts available now in Live!

Get 1:1 Help Now