dbTalk Databases Forums  

Re: Unlocking problem...

comp.databases.paradox comp.databases.paradox


Discuss Re: Unlocking problem... in the comp.databases.paradox forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jim Moseley
 
Posts: n/a

Default Re: Unlocking problem... - 04-04-2007 , 10:14 AM







Kenneth,

I think you also want to check for 'Locked' and 'New', as in:

if (eventInfo.id() = DataPostRecord
and active.RecordStatus("New"))
or (eventInfo.id() = DataUnlockRecord
and (active.RecordStatus("Modified")
or active.RecordStatus("Locked"))) then
ModDate.value = today()
endIf

HTH,
Jim Moseley


Reply With Quote
  #2  
Old   
Jim Moseley
 
Posts: n/a

Default Re: Unlocking problem... - 04-04-2007 , 10:19 AM







Kenneth,

But that probably won't solve your problem.

I'm guessing all of your code is in the Action() method at the form level.
The error occurs because it is trying to handle the unlock/post to the table,
and you are jumping in trying to change another field before it can complete.

The easiest way around this is to delay your update, via a postAction, as
in:

;// following added:

if eventInfo.id() = DataArriveRecord then
; ViewedOn.value = today()
ViewedOn.postAction(userAction + 123)
endIf


And then, in ViewedOn's Action() event, put in this code:

if eventInfo.id() = userAction + 123 then
ViewedOn.value = today()
endif

HTH,
Jim Moseley



Reply With Quote
  #3  
Old   
Jim Moseley
 
Posts: n/a

Default Re: Unlocking problem... - 04-04-2007 , 10:28 AM




Kenneth,

Rereading your original post, you might have to use the postAction() on whatever
you're referring to here:

Quote:
when certain other code
fires on the form, I get the error that the record is
already locked for this session.
Jim Moseley


Reply With Quote
  #4  
Old   
Jim Moseley
 
Posts: n/a

Default Re: Unlocking problem... - 04-04-2007 , 11:09 AM




Kenneth,

I can see how you'd get at least one 'not in edit mode' error, but without
seeing all of your code I can't say what else is wrong.

When you open a form, it will automatically go to the first row in the table
(based on the data model, filters, etc.). It seems like you will always
try to flag this row as Viewed=today(), which I don't think you want.

A form doesn't automatically open in Edit() mode either, so it will arrive
on the row before you can issue the Edit() command, causing the error.

Rather than using dataArriveRecord, is there a common place in your code
where you control which row is displayed on the screen? If so, that is probably
the place for Viewed=today().

If you still want to use dataArriveRecord, then set a global switch once
you've settled onto a 'good' row, and only do the update if it is set. You
can set the switch to false at the beginning of the form's init() method
(before doDefault), then set it to true once you qLocate (or whatever) your
first row.

Also, check your code for EndEdit() or CancelEdit() and either turn off the
switch, or toggle edit() back on just for the Viewed=today() update.

HTH,
Jim Moseley

Reply With Quote
  #5  
Old   
Liz McGuire
 
Posts: n/a

Default Re: Unlocking problem... - 04-04-2007 , 12:05 PM



Try this:

1. Put the stuff in the action event in a switch - only one action
happens at a time, but if you use if blocks, they are all checked - use
a switch.

2. In the second bunch, do this

case eventInfo.id() = DataArriveRecord :
if not isEdit() then
edit()
endIf
doDefault ;// **
ViewedOn.value = today()
ViewedOn.unlockRecord() ;// ***


** I rarely recommend this, but it seems the best option in this
situation. This may well fix the problem entirely - you're probably
trying to write to the field before the arrive is complete enough to
allow it and it's probably another record that's already locked...

*** Unless the ViewedOn field is part of the current index and/or
there's a validity check that hasn't been met, this should be fine. If
it's part of the current index, try dropping this line and see what
happens. If there are validity checks which might not have been met
yet, then you'll have to decide what to do - try without this line, put
it in a try block and in the onFail you can either do errorClear() (the
record stays locked) or something else (post, pop an error, cancel your
edit, whatever - it depends on your needs).

Liz


Kenneth wrote:
Quote:
;// This code executes only for the form:

if eventInfo.id() = DataPostRecord or
(eventInfo.id() = DataUnlockRecord and
active.RecordStatus("Modified"))
then
ModDate.value = today()
endIf

;// following added:

if eventInfo.id() = DataArriveRecord then
ViewedOn.value = today()
endIf

Reply With Quote
  #6  
Old   
Jim Hargan
 
Posts: n/a

Default Re: Unlocking problem... - 04-04-2007 , 09:32 PM



On Wed, 04 Apr 2007 10:30:17 -0400, Kenneth wrote:

Quote:
Howdy,

Originally, I had code on a form to enter today() in a field
called ModDate when something in the underlying tables was
modified using the form. That code looked like this, and
worked fine:

;// This code executes only for the form:

if eventInfo.id() = DataPostRecord or
(eventInfo.id() = DataUnlockRecord and
active.RecordStatus("Modified"))
then
ModDate.value = today()
endIf
I am curious. Why not just put the code in the record's canDepart method?
Then all you need is
if not isEdit()
then
edit()
ModDate'value = today()
endedit()
else
ModDate'value = today()
endif

This won't fire until you leave the first record. If you open the form and
then close it, the first record will record the date this happened during
the close, not during the open.

Off hand, I don't see how this could possibly cause conflicts with other
actions within the form.


Jim Hargan


Reply With Quote
  #7  
Old   
Liz McGuire
 
Posts: n/a

Default Re: Unlocking problem... - 04-09-2007 , 11:12 AM



What if you used dmPut (not sure it won't trigger the unlock code) or a
tcursor (certain it won't trigger the unlock code) to assign the viewed
field? That would avoid having to tweak the mod date code - which I
think would be harder.

Liz


Kenneth wrote:
Quote:
Hi again,

Well, I am having a problem with this after all...

I have a field called "ModDate" that shows today() if there
is any modification to any field on the form.

I also have a field called "Viewed" that shows today() if a
record is viewed, whether or not anything is modified.

Of course, I would not want ModDate to change if there is no
modification to the record, but now, because of the change
to the "Viewed" field, ModDate also changes.

I assume that I can modify the "ModDate" code so that it
"ignores" changes to the "Viewed" field, but I don't know
how to do that.

Here is the ModDate code from the action event of the form:

method action(var eventInfo ActionEvent)

var
endVar
if eventInfo.isPreFilter() then
;// This code executes for each object on the form:
if isEdit() then
if eventInfo.id() = DataRefresh then
eventInfo.setErrorCode(UserError)
endIf
endIf
else
;//This code executes only for the form:

if (eventInfo.id() = DataPostRecord
and active.RecordStatus("New"))
or (eventInfo.id() = DataUnlockRecord
and (active.RecordStatus("Modified")
or active.RecordStatus("Locked"))) then
ModDate.value = today()
endIf
endIf
endMethod

Can you suggest the modification I need?

Sincere thanks,

Reply With Quote
  #8  
Old   
Liz McGuire
 
Posts: n/a

Default Re: Unlocking problem... - 04-09-2007 , 12:01 PM



Um, moving to the right record? Try tc.attach(UIObject).

LIz


Kenneth wrote:
Quote:
Hi Liz,

I just put this on the arrive of the field where I had the
other code:

method arrive(var eventInfo MoveEvent)
var
tc1 tCursor
endVar

if not tc1.open ("ATA: demograf.db") then errorShow()
endIf
if not tc1.edit() then errorShow() endif
tc1.Viewed = today()
if not tc1.endEdit() then errorShow() endif

endMethod


It generates no error, but it does not write today's date to
the table.

What am I missing?

Thanks,

Reply With Quote
  #9  
Old   
Tony McGuire
 
Posts: n/a

Default Re: Unlocking problem... - 04-09-2007 , 12:14 PM




Quote:
Um, moving to the right record? Try tc.attach(UIObject).
And don't forget to close the tcursor!

And don't forget, you *may* have to forcerefresh() of the UI before it will
display!


--
------------------------------
Tony McGuire




Reply With Quote
  #10  
Old   
Liz McGuire
 
Posts: n/a

Default Re: Unlocking problem... - 04-09-2007 , 03:04 PM



Check the syntax - you need to attach it to an object on the form which
is bound to the table with the field you want to update - tableframe,
field, MRO.

Liz


Kenneth wrote:
Quote:
Hi Liz,

Of course, that is the problem, but I need some further
help.

I can't figure out how to make the attach work properly.
Should I be attaching the tCursor to the form or to
something on the form? I've read the appropriate help file
entry, but don't get it.

Thanks again,

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.