1

I face the following error when I try to debug. I am just newbie with Delphi, please guide how to correct this error.

First chance exception at $73B1A9F2. Exception class EAccessViolation with message 'Access violation at address 005D3653 in module 'Project1.exe'. Read of address 000003AC'. Process Project1.exe (34780)

When break this source code is shown:

  if fsCreating in FFormState then
    if Value then
      Include(FFormState, fsVisible) else
      Exclude(FFormState, fsVisible)
kobik
  • 21,001
  • 4
  • 61
  • 121
Fiaz
  • 30
  • 2
  • 9
  • 6
    look at the call stack, the defect is somewhere in your code... – whosrdaddy Jul 31 '17 at 07:06
  • 5
    Is "When break;" really part of your code? What is it you are showing us? – Dsm Jul 31 '17 at 07:36
  • @Dsm when i click on break it takes me to vCL.forms page and pointing at if fsCreating in FFformState then – Fiaz Jul 31 '17 at 08:30
  • @LievenKeersmaekers: It was meant as a kind hint as the OP is clearly showing VCL code... – whosrdaddy Jul 31 '17 at 08:37
  • access violation means you are trying to use an object that has not been created yet ,or after it has been destroyed. So check your code for possible use of not created objects – GuidoG Jul 31 '17 at 09:28
  • @FiazAhmad The code that you showed is part of `TCustomForm.SetVisible` method. Since that method is used when you are changing form `Visible` property it most likely means that you are trying to change the `Visible` property on a form that hasn't been created yet, So make sure your forms are already created before trying to change any of their properties. – SilverWarior Jul 31 '17 at 21:01

1 Answers1

4

You are calling a method on an invalid reference. For instance something like

Obj.DoSomething;

where Obj is not valid. Because the attempted read address is 000003AC, close to zero, almost certainly the reference is nil.

Track back up your call stack until you find the call with the nil reference.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • 1
    FWIW, `000003AC` is not very close to 0, so it must be a larger structure, e.g. an array or some such ($3AC is 1100, so an array of at least 275 pointers or integers or similar). – Rudy Velthuis Jul 31 '17 at 10:14
  • 2
    @RudyVelthuis Well, `InstanceSize` for `TForm` on XE7 is `000003B4` so yeah, I think my answer is pretty accurate. Don't you agree? – David Heffernan Jul 31 '17 at 10:21
  • 1
    Well, then that matches what I said, doesn't it? – Rudy Velthuis Jul 31 '17 at 12:28
  • No. You implied that the address was too large to be an offset from zero. I demonstrated otherwise. – David Heffernan Jul 31 '17 at 12:30
  • 1
    I implied that the address was pretty large (i.e. at quite an offset from nil), indicating what it could be.So yes, that is what I said. I did not check if that was close to the size of TForm. – Rudy Velthuis Jul 31 '17 at 12:31
  • OK, so you agree that it is most likely that this is a nil reference? – David Heffernan Jul 31 '17 at 13:42
  • Of course. I never said otherwise. But the exact address (i.e. the offset from nil) can sometimes be very indicative too. – Rudy Velthuis Jul 31 '17 at 14:13
  • If we knew what version was used then of course we could know precisely the pertinent offset. It's fairly obviously FFormStyle – David Heffernan Jul 31 '17 at 14:32
  • 1
    Hmmm.. given the snippet posted, I'd rather bet on FFormState. Is that what you meant? – Rudy Velthuis Jul 31 '17 at 15:02
  • Yes, that's what I meant, commenting on a phone.... – David Heffernan Jul 31 '17 at 15:28
  • 1
    Guys stop wasting time arguing whether the specified address is close to 0 or not. If you would instead take this time to find where provided code sample can be found you would see that it is a part of `TCustomForm.SetVisible` method that is being used by forms `Visible` property which would tell you the reason why the access violation is raised. Oh and the address returned by the access violation is not merely affected by the `TForm` instance size because it is not necessary that such instance would be the first class instance created. – SilverWarior Jul 31 '17 at 21:10
  • @Silver Now you start talking about what the address means and make statement that is utterly bogus. Final sentence in your comment is completely wrong. – David Heffernan Aug 01 '17 at 06:09