Solved

Updating a Paradox record

Posted on 1998-11-11
13
292 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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
 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi XE10, MySQL Query 4 164
Simple Delphi Question 9 96
Communication Between RC4 Delphi <-> PHP 3 123
Installshield for Embarcadero EX 10.1 Berlin 4 60
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

860 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