delphi - Delphi 中的堆栈溢出

标签 delphi function stack-overflow skype

我正在 StackOverflow.com 上发布我的 Stack Overflow 问题。讽刺是最好的!

无论如何。我在 SkypeReply 事件处理程序上调用此过程,该处理程序被多次触发:

  Procedure OnCategoryRename;
  Var
    CategoryID : Integer;
    sCtgName : String;
  Begin
    if (AnsiContainsStr(pCommand.Reply,'GROUP')) and (AnsiContainsStr(pCommand.Reply,'DISPLAYNAME')) then
      begin
         sCtgName := pCommand.Reply;
         Delete(sCtgName,1,Pos('GROUP',sCtgName)+5);
         CategoryID := StrToInt(Trim(LeftStr(sCtgName,Pos(' ',sCtgName))));
         sCtgName := GetCategoryByID(CategoryID).DisplayName; // Removing THIS line does not produce a Stack Overflow!
         ShowMessage(sCtgName); 
      end;

这样做的想法是循环遍历我的 Skype 组列表,以查看哪个组已重命名。据我所知,这并不重要,因为我的 S.O 被发现出现在这里

Function GetCategoryByID(ID : Integer):IGroup;
Var
  I : Integer;
  Category : IGroup;
Begin
  // Make the default result nil
  Result := nil;

  // Loop thru the CUSTOM CATEGORIES of the ONLY SKYPE CONTROL used in this project
  // (which 100% positive IS attached ;) )
  for I := 1 to frmMain.Skype.CustomGroups.Count do
    Begin
      // The Category Variable
      Category := frmMain.Skype.CustomGroups.Item[I];
      // If the current category ID returned by the loop matches the passed ID
      if Category.Id = ID then
        begin
          // Return the Category as Result (IGroup)
          Result := Category;
          // Exit the function.
          Exit;
        end;
    End;
End;

当我在 Result := Category; 设置断点时和单步执行,这两行会一遍又一遍地执行!

当我注释掉第一个代码片段中的 sCtgName := GetCategoryByID(CategoryID).DisplayName; 时,没有溢出,消息显示时间应该到了。但是,GetCategoryByID是我编写的一个函数,我也编写了一个类似的函数,它工作得很好(GetCategoryByName),所以我不明白为什么它决定重复

// Return the Category as Result (IGroup)
Result := Category;
// Exit the function.
Exit;

一遍又一遍。

编辑:以下是重现它的方法:https://gist.github.com/813389

编辑:这是我的 CallStack,根据要求: CallStack

编辑2:更多信息: More Info

最佳答案

确保在关闭“优化”、打开“堆栈帧”和“使用调试.dcu”的情况下编译项目,以获得尽可能详细的调用堆栈。然后在此处发布当您遇到堆栈溢出时获得的调用堆栈(如果您无法从中识别问题的性质)。

关于delphi - Delphi 中的堆栈溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4909511/

相关文章:

android - 为什么 Delphi 10.3 应用程序在 Android 11 中崩溃?

delphi - 来自 TCustomWinSocket 的 ReceiveBuf 不适用于缓冲区的动态数组

windows - 如何在 Delphi 中处理自定义组件中的箭头键?

javascript - 将 Get 方法结果存储到变量中并显示它

linux - 在 bash shell 中使用 scp 时出现段错误(核心已转储)

c# - 执行 FloodFill 的不同方法

delphi - 为什么无法使用 WinExec 启动 Windows Update 控制面板?

javascript - 为选定的单选按钮 div 添加类名称

swift - 如何修复此无法识别的选择器发送到实例错误?

c - 在 c 中每个函数都有自己的堆栈吗?