I had to move the @SelectTree command over to the Track Title LE like this:
[Code for On Entry to LE named Delete in the subform]
GlobalValue("Recalculate", 1)
ThrowFocus(Track Title)
[Code for On Entry to LE named Track Title in the subform]
var vDelete as Int
var vLoop as int
var vTime as time
var vCnt as int
if @GlobalValue("Recalculate") = 1
{
GlobalValue("Recalculate", 0)
vDelete = @SelectTreeItem("Search Update Menu!Record Commands!Delete Record (F3)")
vCnt = @FormResultSetTotal("Track Details")
vLoop = 1
vTime = 0
while vLoop <= vCnt
{
vTime = vTime + @ToTime( @FormFieldValue("Track Details", "Track Length", vLoop) )
vLoop += 1
}
FormFieldValue("MyMainForm", "MyTimeLE", 0, vTime)
}
This works fine the first time you click on the "Delete" LE. But after that, ThrowFocus doesn't trigger the On Element Entry event. This may be a bug with Sesame - the fact that the On Element Entry & On Element Exit events are not executing when focus is moved with ThrowFocus. They do execute if focus is moved with a mouse-click. But, because the events are not working the way that the code expects it to, the GlobalValue may not get reset to zero. Then the code may execute when you click on the Track Title element in another record, deleting that other record.
So, if the On Element Entry event was triggered by the ThrowFocus command, the code above would work perfectly. But, since it is not, I have had to completely rearrainge things. This is the best I could come up with:
[Delete :: On Element Entry]
if @IsBlank(Delete)
{
Delete = "X"
ThrowFocus(Track Title)
}
[Track Details (YourSubformName?) :: On Element Exit]
var vDelete as Int
var vLoop as int
var vTime as time
var vCnt as int
if Delete = "X"
{
vCnt = @FormResultSetTotal("Track Details")
vDelete = @SelectTreeItem("Search Update Menu!Record Commands!Delete Record (F3)")
if vCnt = @FormResultSetTotal("Track Details") then Clear(Delete)
vCnt = @FormResultSetTotal("Track Details")
vLoop = 1
vTime = 0
while vLoop <= vCnt
{
vTime = vTime + @ToTime( @FormFieldValue("Track Details", "Track Length", vLoop) )
vLoop += 1
}
FormFieldValue("MainForm", "MainFormTimeLE", 0, vTime)
}
This works pretty well. The main drawback, is that you need to click in the Delete element, then click in any other subform element (or on another line in the subform). Which means it requires 2 clicks to get the warning message about deleting a record.
One caution: don't answer yes to the question if clicking in the parent form is what brought it up. That may delete the parent form. Other than those two things, it works quite well.
One thing that works better now, is that there will be an "X" on the record that you are being asked whether or not to delete - helping to clarify which line you clicked on. If you answer no to the question, the Delete element is cleared.