MIDISetEvent() can delete the currently selected track. When a track is deleted, all events in it are deleted, including any End of Track event. You specify the DEL option, and pass a -1 for the second arg. Here we delete the currently selected track:
/* Delete the track and check for an error */
err = MIDISetEvent('DEL', -1)
IF err \== "" THEN SAY err
When the currently selected track is deleted, then there is no longer a currently selected event/track.

Here we delete all tracks containing data:

/* Reset the shortcut increment */
MIDITrack(0)

/* Set each non-empty track in turn */
WHILE MIDITrack("") \== 0 THEN DO

   /* Delete the track */
   err = MIDISetEvent('DEL', -1)

   /* Check for an error */
   IF err \== "" THEN DO
      SAY err
      LEAVE
   END

END