• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

Updating a Paradox record

How can I prevent 2 users in a network to change the same Paradox record at the same time?
0
rainbowsoftware
Asked:
rainbowsoftware
  • 6
  • 2
  • 2
  • +2
1 Solution
 
kretzschmarCommented:
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
 
SupWangCommented:
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
 
kretzschmarCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
rainbowsoftwareAuthor Commented:
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
 
kretzschmarCommented:
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
 
rpetruniCommented:
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
 
kretzschmarCommented:
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
 
elkiorsCommented:
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
 
kretzschmarCommented:
Hello? Is somebody here?
0
 
elkiorsCommented:
I'm here but only because you posted, the message.

Darren

0
 
kretzschmarCommented:
Hello, some other here except darren?
0
 
rainbowsoftwareAuthor Commented:
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
 
rpetruniCommented:
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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now