Following is some code I am trying to perfect to insert and delete lines in an embedded browse. It runs from the OnKey event of the form.
The browse table has a 'line' field that is indexed and the browse is sorted by the line field.
The insert portion works the first time but then it adds duplicate lines numbers after the first insert. I think it has something to do with the indexes, because if I insert one line and then look at the table the new line is at the bottom. I tried tbl.index_primary_put("Line") after table.open, but it locks up. I probably need to update the indexes, but not sure how. Or is there a better way to do this?
The delete portion works down to deleting the record, but it doesn't renumber the lines like I want it to.
Any ideas?
Dan
The browse table has a 'line' field that is indexed and the browse is sorted by the line field.
The insert portion works the first time but then it adds duplicate lines numbers after the first insert. I think it has something to do with the indexes, because if I insert one line and then look at the table the new line is at the bottom. I tried tbl.index_primary_put("Line") after table.open, but it locks up. I probably need to update the indexes, but not sure how. Or is there a better way to do this?
The delete portion works down to deleting the record, but it doesn't renumber the lines like I want it to.
Any ideas?
Code:
if this.Active() = "Browse1" then if a_user.key.value = "{^INSERT}" a_user.key.handled = .T. if parentform.mode_get()<> "View" topparent.commit() end if if a_user.key.event = "down" if this.Table_Get().Mode_Get() > 0 then this.Commit() end if 'First get the current line number and then 'renumber the lines starting with the current line dim vLine1 as C dim vLine2 as C vLine1 = parentform:browse1.line.value vLine2 = vLine1 dim tbl as P tbl = table.open("salesdetails2") ' tbl.index_primary_put("Line") tbl.fetch_first() while .not. tbl.fetch_eof() if tbl.Line = vLine1 then vLine1 = val(vLine1) + 1 vLine1 = padl(vLine1,2,"0") tbl.change_begin() tbl.line = vLine1 tbl.change_end(.t.) end if tbl.fetch_next() end while tbl.close() 'Then insert the new line parentform:browse1.new_record() parentform:browse1.line.value = vLine2 parentform:browse1.commit() end if end if end if if this.Active() = "Browse1" then if a_user.key.value = "{^DELETE}" a_user.key.handled = .T. if parentform.mode_get()<> "View" topparent.commit() end if if a_user.key.event = "down" if this.Table_Get().Mode_Get() > 0 then this.Commit() end if parentform:browse1.delete_record() 'Renumber lines dim tbl as P dim vLine as C vLine = "0" tbl = table.open("salesdetails2") tbl.fetch_first() while .not. tbl.fetch_eof() vLine = val(vLine) + 1 vLine = padl(vLine,2,"0") tbl.change_begin() tbl.line = vLine tbl.change_end(.t.) tbl.fetch_next() end while tbl.close() end if end if end if
Comment