delphi – Stack Overflow

前端之家收集整理的这篇文章主要介绍了delphi – Stack Overflow前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
嘿S.O!我在StackOverflow.com上发布了Stack Overflow问题.讽刺最好!

无论如何.我在我的SkypeReply事件处理程序上调用此过程,该事件被解雇了很多:

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

这样做的想法是通过我的Skype群组列表循环,以查看已重命名的群组. AFAIK并不重要,因为我的S.O被追溯到这里出现

  1. Function GetCategoryByID(ID : Integer):IGroup;
  2. Var
  3. I : Integer;
  4. Category : IGroup;
  5. Begin
  6. // Make the default result nil
  7. Result := nil;
  8.  
  9. // Loop thru the CUSTOM CATEGORIES of the ONLY SKYPE CONTROL used in this project
  10. // (which 100% positive IS attached ;) )
  11. for I := 1 to frmMain.Skype.CustomGroups.Count do
  12. Begin
  13. // The Category Variable
  14. Category := frmMain.Skype.CustomGroups.Item[I];
  15. // If the current category ID returned by the loop matches the passed ID
  16. if Category.Id = ID then
  17. begin
  18. // Return the Category as Result (IGroup)
  19. Result := Category;
  20. // Exit the function.
  21. Exit;
  22. end;
  23. End;
  24. End;

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

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

  1. // Return the Category as Result (IGroup)
  2. Result := Category;
  3. // Exit the function.
  4. Exit;

一遍又一遍地.

如果您需要更多信息,请不要犹豫!

编辑:以下是如何重现它:https://gist.github.com/813389

编辑:这是我的CallStack,按要求:

Edit2:更多信息:

谢谢你的时间!
– 杰夫

解决方法

您的问题中没有显示内容
你在这里发布的“OnCategoryRename”函数是一个从“TForm.Skype1Reply”回调调用的子函数.

要看到这一点,我必须点击你的github链接 – 但我认为这是你问题的重点.

我猜 :

>您的“GetCategoryById”函数实际上发送一个查询,触发“Skype1Reply”.
>如果组名已更改,“Skype1Reply”将调用“OnCategoryRename”.
>“OnCategoryRename”调用“GetCategoryById”
>“GetCategoryById”触发“Skype1Reply”
>不知何故,测试说“如果groupname已经改变”仍然是真的,所以“Skype1Reply”调用“OnCategoryRename”
>“OnCategoryRename”调用“GetCategoryById”
>冲洗,重复

我认为快速而肮脏的解决办法是改变

  1. sCtgName := GetCategoryByID(CategoryID).DisplayName; // Removing THIS line does not produce a Stack Overflow!

  1. sCtgName := //find another way to get the new name,which you can probably get from your ICommand object
  2. pCommand.Reply.ReadDataFromReplyAndGetNewDisplayName;

将来,我建议您发布此类问题的完整代码示例.

猜你在找的Delphi相关文章