错误Delphi XE2 - 异常类$ C00000005 [英] Error Delphi XE2 - Exception class $C00000005

查看:1575
本文介绍了错误Delphi XE2 - 异常类$ C00000005的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到这个错误会调试一个项目,以前在Delphi 7中,我已经升级到Delphi XE2,同样的错误发生在几种方法中。

I am getting this error will debugging a project, which used to be in Delphi 7 and I have been upgrading to Delphi XE2, the same error happens in several methods.

First chance exception at $006DC660. Exception class $C0000005 with message 'access violation at 0x006dc660 read of address 0xffffffff' 

这是方法:

PFI = ^TFI;           
TFI = record
Id         : TToken;
Name       : TName;
Parameters : string;
end;

function TListFI.IsIn(S: PChar): PFI;

  function SearchName2(Item: PFI):Boolean;
  var N1, N2: PChar;
  begin
    N1:= StrNew(Item^.Name);
    N2:= StrNew(S); //Here is the issue
    SearchName2:= (StrComp(StrUpper(N1), StrUpper(N2)) = 0);
    StrDispose(N1);
    StrDispose(N2);
  end;

begin
  IsIn:= PFI(FirstThat(@SearchName2));
end;

我已经google了,我找到一个描述类似问题的人,他肯定当增量链接器禁用它的工作,有人可以告诉我什么是在哪里或在哪里或提供一些建议来解决这种情况。

I have googled and I found someone describing a similar problem, and he affirms that when the incremental linker is disabled it works, can someone tell me what and where is it or give some advice to solve this situation.

删除@现在给我在IsIn:= PFI(FirstThat(SearchName2))中的以下错误;

Removing the @ now gives me the following error in IsIn:= PFI(FirstThat(SearchName2));

E2010 Incompatible types: 'TObject' and 'PFI'

我添加了FirstThat过程来查看可能有帮助。

I am adding the FirstThat procedure to see if it may help.

TFuncionColeccion = function (Elemento: TObject): Boolean;

function TColeccion.FirstThat (Rutina: TFuncionColeccion): TObject;
var
  i: Integer;
begin
  For i:=0 to Count-1 do
    if Rutina(Items[i]) then
    begin
      FirstThat:=Items[i];
      exit;
    end;
  FirstThat:=nil;
end;


推荐答案

这是(并且一直是)一个错误通过指针调用本地(嵌套)过程,这显然是你的 FirstThat 函数所做的。编译器必须使用堆栈来做特殊的事情来调用本地函数,并让他们访问父范围的变量(代码中的 S ),但编译器只能知道当直接调用本地函数时,做这些特殊的事情。编译器不知道 FirstThat 的参数将是本地函数,所以当 FirstThat 调用指向函数。

It is (and always has been) an error to call local (nested) procedures by pointer, which is clearly what your FirstThat function does. The compiler has to do special things with the stack to call local functions and give them access to the parent scope's variables (S in your code), but the compiler can only know to do those special things when the local function is called directly. The compiler cannot know that the argument to FirstThat will be a local function, so it doesn't include the special code when FirstThat invokes the pointed-to function.

底线是函数内的堆栈不会按照它的方式设置,这意味着任何可能出现奇怪症状的数量。你必须使用其他方法。可能使 SearchName2 成为一个双参数函数,然后写入 FirstThat 接受 S 作为参数,它可以转发到函数参数。

The bottom line is that the stack inside the function doesn't get set up the way it's supposed to, and that means any number of strange symptoms may appear. You'll have to use some other way. Maybe make SearchName2 be a two-argument function, and then write FirstThat to accept S as a parameter that it can forward to the function argument.

您不需要使用 @ 运算符构造函数指针。当你这样做时,编译器倾向于跳过类型检查,这样你可以首先将本地函数指针传递给 FirstThat 。当您传递的函数真正匹配所需的原型时,编译器将允许您传递它,而不需要 @ 运算符。

You shouldn't need to use the @ operator when constructing a function pointer. When you do, the compiler tends to skip type checking, which is what allowed you to pass a local function pointer to FirstThat in the first place. When the function you're passing really matches the required prototype, the compiler will allow you to pass it without the @ operator.

这篇关于错误Delphi XE2 - 异常类$ C00000005的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆