dbTalk Databases Forums  

Re: dataInsertRecord not Insertin'...?

comp.databases.paradox comp.databases.paradox


Discuss Re: dataInsertRecord not Insertin'...? in the comp.databases.paradox forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Tony McGuire
 
Posts: n/a

Default Re: dataInsertRecord not Insertin'...? - 01-09-2009 , 09:53 AM






Kenneth wrote:
Quote:
method action(var eventInfo ActionEvent)
var
tc2 tCursor
endVar

if eventInfo.id()=dataInsertRecord then

DoDefault

if not tc2.open(":MONEY:EntryNum.DB") then
errorShow()
endIf

EntryNumber = tc2.entryNum

tc2.edit()
tc2.entryNum = EntryNumber + 1
edit()
entry = tc2.entryNum
tc2.endEdit()
tc2.close()

endIf
endMethod
You have 'edit()' as part of the routine INSIDE the if eventinfo.id() block.

Are you sure it is in edit mode to start with? Cause the above would fail the
first time and work (likely) the second and subsequent times (sound like what
you are getting?) if the form wasn't in edit to start.

Also, if the tc2.open you have errorshow(); I would add 'return' to that since
you don't want errors cropping up when your code starts referencing a tcursor
that didn't get opened.

Is this code going to be used by more than one person; ever? Actully, the
table 'entrynumb.db'. If so, this code needs (critically) to be revisited
once you get the main issue resolved.

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


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

Default Re: dataInsertRecord not Insertin'...? - 01-09-2009 , 12:02 PM






Actually, Tony referred to the edit() statement, not the endedit. What
exactly does an Edit() statement do without an associated object? I'm used
to saying myTc.edit() or something like that so I know what exactly is going
into edit mode.
"Kenneth" <usenet (AT) soleSPAMLESSassociates (DOT) com> wrote

Quote:
On Fri, 09 Jan 2009 08:53:02 -0700, Tony McGuire
png.paradoxcommunity@com> wrote:

Kenneth wrote:

method action(var eventInfo ActionEvent)
var
tc2 tCursor
endVar

if eventInfo.id()=dataInsertRecord then

DoDefault

if not tc2.open(":MONEY:EntryNum.DB") then
errorShow()
endIf

EntryNumber = tc2.entryNum

tc2.edit()
tc2.entryNum = EntryNumber + 1
edit()
entry = tc2.entryNum
tc2.endEdit()
tc2.close()

endIf
endMethod

You have 'edit()' as part of the routine INSIDE the if eventinfo.id()
block.

Are you sure it is in edit mode to start with? Cause the above would fail
the
first time and work (likely) the second and subsequent times (sound like
what
you are getting?) if the form wasn't in edit to start.

Also, if the tc2.open you have errorshow(); I would add 'return' to that
since
you don't want errors cropping up when your code starts referencing a
tcursor
that didn't get opened.

Is this code going to be used by more than one person; ever? Actully, the
table 'entrynumb.db'. If so, this code needs (critically) to be revisited
once you get the main issue resolved.

Hi Tony,

I removed the endEdit() as you suggested.

Now, if I launch the form, and touch the Insert Key, a new
blank record opens as it should, but the Entry Number
increments by 2, rather than 1.

If I then populate that record, and touch Insert again, a
new blank record opens and the counter increments by 1.

Also, this is STRICTLY a one person form, and so there is no
issue with regard to properly locking the entrynum.db.

Very sincere thanks for your help,
--
Kenneth

If you email... Please remove the "SPAMLESS."



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

Default Re: dataInsertRecord not Insertin'...? - 01-09-2009 , 12:33 PM



On Fri, 9 Jan 2009 13:02:57 -0500, Jim Giner wrote:

Quote:
Actually, Tony referred to the edit() statement, not the endedit. What
exactly does an Edit() statement do without an associated object? I'm used
to saying myTc.edit() or something like that so I know what exactly is going
into edit mode.
Edit() without an associated object becomes a uiObject method, and (like
all such 'bare' uiObject methods) is interpreted as self.Edit().

That is -- as far as I can figure out. Bare uiObject methods confused the
heck out of me for many years, and this interpretation seems to work
consistently.

FWIW,

--
Jim Hargan


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

Default Re: dataInsertRecord not Insertin'...? - 01-09-2009 , 01:27 PM



Inline.

On Fri, 09 Jan 2009 10:23:19 -0500, Kenneth wrote:
Quote:
method action(var eventInfo ActionEvent)
var
tc2 tCursor
endVar

if eventInfo.id()=dataInsertRecord then
DoDefault
; The doDefault inserts the record /if/ the form is in edit mode.
; Otherwise, it fails, and no record has been added.

Quote:
if not tc2.open(":MONEY:EntryNum.DB") then
errorShow()
endIf
; At this point tc2 is pointing to the table, but it is unclear
; to me which record it is pointing to. I expect it points to the first
; record.

Quote:
EntryNumber = tc2.entryNum
; This should be the entryNum of whatever record is the first one in
; the table.

Quote:
tc2.edit()
; This puts the *tCursor* into edit mode.

Quote:
tc2.entryNum = EntryNumber + 1
; This alters the first record's entryNum by incrementing it.
; Note that you are changing its primary key!

Quote:
edit()
; This puts the *form* into edit mode.

Quote:
entry = tc2.entryNum
; At this point entry -- which I assume is a uiObject on the form that
; corresponds to a field in the table -- equals the first record's
; entryNum, which you incremented three steps ago.

Quote:
tc2.endEdit()
; This posts the change you made to the first record via the tCursor.
; The change you made to the record shown by the form, which may or may
; not be a different record, has not yet been posted.

Quote:
tc2.close()

endIf
endMethod
OK, lemme make a suggestion.
First, I am assuming that entryNum is the table's primary key. This means
that, when the tCursor opens on the table and points to the first record,
it will be pointing to the record with the /lowest/ entryNum, and that the
last record will be the one with the /highest/ entryNum.

var
flg logical
tc2 tCursor
li longint
endVar

flg = FALSE
if not isEdit() then
flg = TRUE
edit()
endif ;This lets us restore the user's edit setting at the end
;Now the form is in edit mode, and the insert can work.

if eventInfo.id()=dataInsertRecord then

;The tCursor exists merely to get the highest value,
;so we do the tCursor thing /before/ creating the new record
if not tc2.open(":MONEY:EntryNum.DB") then
msgStop("Error","New record not created because the tCursor failed")
return ;execution stops - no new record added
endIf
tc2.end()
;tc2 should now be pointing to the record with the highest entryNum
li = tc2.entryNum
tc.2.close()

;We are now back to the form, and using uiObjects
DoDefault ;creates the new record
li = li + 1
entry.value = li
postRecord() ;pushes the new record into the table
endif

if flg then ;restore the user's edit setting
endedit()
endif

Again, this is untested. The gist of it should be ok. I hope.

--
Jim Hargan


Reply With Quote
  #5  
Old   
Jim Giner
 
Posts: n/a

Default Re: dataInsertRecord not Insertin'...? - 01-09-2009 , 01:44 PM



Jim - I'm guessing that tc2 is pointing to a one record table - without a
key. It's the way he increments his form's record keys.
"Jim Hargan" <contact (AT) harganonline (DOT) com> wrote

Quote:
Inline.

On Fri, 09 Jan 2009 10:23:19 -0500, Kenneth wrote:
method action(var eventInfo ActionEvent)
var
tc2 tCursor
endVar

if eventInfo.id()=dataInsertRecord then
DoDefault
; The doDefault inserts the record /if/ the form is in edit mode.
; Otherwise, it fails, and no record has been added.

if not tc2.open(":MONEY:EntryNum.DB") then
errorShow()
endIf
; At this point tc2 is pointing to the table, but it is unclear
; to me which record it is pointing to. I expect it points to the first
; record.

EntryNumber = tc2.entryNum
; This should be the entryNum of whatever record is the first one in
; the table.

tc2.edit()
; This puts the *tCursor* into edit mode.

tc2.entryNum = EntryNumber + 1
; This alters the first record's entryNum by incrementing it.
; Note that you are changing its primary key!

edit()
; This puts the *form* into edit mode.

entry = tc2.entryNum
; At this point entry -- which I assume is a uiObject on the form that
; corresponds to a field in the table -- equals the first record's
; entryNum, which you incremented three steps ago.

tc2.endEdit()
; This posts the change you made to the first record via the tCursor.
; The change you made to the record shown by the form, which may or may
; not be a different record, has not yet been posted.

tc2.close()

endIf
endMethod

OK, lemme make a suggestion.
First, I am assuming that entryNum is the table's primary key. This means
that, when the tCursor opens on the table and points to the first record,
it will be pointing to the record with the /lowest/ entryNum, and that the
last record will be the one with the /highest/ entryNum.

var
flg logical
tc2 tCursor
li longint
endVar

flg = FALSE
if not isEdit() then
flg = TRUE
edit()
endif ;This lets us restore the user's edit setting at the end
;Now the form is in edit mode, and the insert can work.

if eventInfo.id()=dataInsertRecord then

;The tCursor exists merely to get the highest value,
;so we do the tCursor thing /before/ creating the new record
if not tc2.open(":MONEY:EntryNum.DB") then
msgStop("Error","New record not created because the tCursor failed")
return ;execution stops - no new record added
endIf
tc2.end()
;tc2 should now be pointing to the record with the highest entryNum
li = tc2.entryNum
tc.2.close()

;We are now back to the form, and using uiObjects
DoDefault ;creates the new record
li = li + 1
entry.value = li
postRecord() ;pushes the new record into the table
endif

if flg then ;restore the user's edit setting
endedit()
endif

Again, this is untested. The gist of it should be ok. I hope.

--
Jim Hargan



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

Default Re: dataInsertRecord not Insertin'...? - 01-09-2009 , 02:32 PM



Jim Hargan wrote:
Quote:
On Fri, 9 Jan 2009 13:02:57 -0500, Jim Giner wrote:

Actually, Tony referred to the edit() statement, not the endedit. What
exactly does an Edit() statement do without an associated object? I'm used
to saying myTc.edit() or something like that so I know what exactly is going
into edit mode.

Edit() without an associated object becomes a uiObject method, and (like
all such 'bare' uiObject methods) is interpreted as self.Edit().

That is -- as far as I can figure out. Bare uiObject methods confused the
heck out of me for many years, and this interpretation seems to work
consistently.

FWIW,

--
Jim Hargan
You can get away with edit() in an object on a form; it puts the underlying
table into edit mode.

But since he does all this stuff without necessarily putting the form into
edit mode, or testing whether it is in edit mode, the FIRST time through you
won't necessarily get a record added to work on.

But then, since the endedit() was associated with the tcursor and not the form
or its underlying table, NOW the form/table is in edit mode and thus it all works.

At the start of the form, page open usually, I ALWAYS have
if not isedit() then
edit()
endif

if I or a user will be doing any work on the form entailing editing the
underlying table(s).



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


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

Default Re: dataInsertRecord not Insertin'...? - 01-09-2009 , 05:10 PM



On Fri, 9 Jan 2009 14:44:52 -0500, Jim Giner wrote:

Quote:
Jim - I'm guessing that tc2 is pointing to a one record table - without a
key. It's the way he increments his form's record keys.
Doh! Shoulda guessed.

--
Jim H


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

Default Re: dataInsertRecord not Insertin'...? - 01-09-2009 , 10:28 PM



Kenneth wrote:
Quote:
if not tc2.open(":MONEY:EntryNum.DB") then
errorShow()
endIf


I would still do

if not tc2.open(":MONEY:EntryNum.DB") then
errorshow("Error - EntryNum.db")
; "Error.." becomes the title of the errorshow() dialog box
return
endif

Otherwise, you'll at some point not be able to open entrynum.db, and Paradox
will start erroring out on the code below that, and quite possibly confusing
the heck out of what the problem is for you. Simple change to make your life
easier later.

Glad you finally found Nirvana.


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


Reply With Quote
  #9  
Old   
Dennis Santoro
 
Posts: n/a

Default Re: dataInsertRecord not Insertin'...? - 01-10-2009 , 11:04 AM



Sorry I'm late to the party.

In addition ot what the others have told you that helped you slove the
problem and Tony's suggestion about adding errorshow labels you should
also test anything that can fail

if not myTCToKeyIncrementTable.endedit() then
errorshow("can't end edit on key table")
endif

Also, use a naming convention that makes your code more readable (see
the faq on naming conventions).

Finally, learn to liberally comment your code so you know what is going
on and to help others who may have to look at your code in the future.

Denn Santoro
President
Resource Development Associates
http://www.RDAWorldWide.Com
Offices in the United States and Germany
Providing solutions to health care, business, governments and
non-profits since 1982

Kenneth wrote:

Quote:
Tony McGuire

Hi Tony,

Well, I don't know about Nirvana, but I am pleased to have
it working, and have incorporated your errorShow suggestion.

Many thanks, as before,

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.