Jessé Catrinck
Jessé Catrinck

Reputation: 2277

Delphi strange inaccessible value (acess violation) o.O

Self is set but Self.Img inaccessible

Self contains Img but Self.Img is inaccessible

Upvotes: 3

Views: 7348

Answers (2)

David Heffernan
David Heffernan

Reputation: 612874

Inaccessible value in a watch can mean one of two things, in my experience:

  1. A value that cannot be evaluated because of, for instance, an access violation, or
  2. A value that cannot be evaluated by the debugger because of insufficient debug information, optimization or similar.

The first explanation would tally with you seeing an access violation. Indeed, I tried to re-create your scenario with this code:

{$APPTYPE CONSOLE}

uses
  SysUtils, Classes;

type
  TMyClass = class
    Img: TComponent;
    procedure foo;
  end;

procedure TMyClass.foo;
begin
  Img := TComponent($deadbeef);
end;

begin
  TMyClass.Create.foo;
end.

I set a break point after the assignment to Img in TMyClass.foo, and the watch list looked like this:

enter image description here

So all the indications are that, in your code, Img points to inaccessible memory.

The debugger will be able to confirm this for you. If the line that you have broken executes and produces an access violation then either Self or Self.Img is invalid. The evidence is that Self is fine. But you should be able to debug this without much trouble.

Upvotes: 5

Mason Wheeler
Mason Wheeler

Reputation: 84540

What "Inaccessible value" means is that the reference to this value is not valid, and would give an access violation if dereferenced, which the title of your post seems to indicate is what is happening.

Is this debug data showing values from before the access violation was raised, or after it? Having an exception raised can really screw up what the debugger shows at the top of the call stack, and data from the top few frames should not be trusted.

If this is before the exception was raised, that means you've got corrupt data somewhere. Is there only one (or a small number of) TPerson object(s) being created? If so, you can put a breakpoint in the constructor and set a data breakpoint on the Img field, and it'll break when the value changes, which will help you track down the corruption.

Upvotes: 5

Related Questions