错误大概在这里:
while HistoryList.Count >HistoryIndex do
          HistoryList.Delete(HistoryIndex);