M
M
mergenich2016-05-31 13:01:19
Delphi
mergenich, 2016-05-31 13:01:19

Why access violation in the constructor?

Created this class:

type
  Painter = class
  public
    constructor Create();
  private
    sprite: TBitmap;
  end;

constructor Painter.Create();
begin
  sprite := TBitmap.Create;
end;

I run - error:
First chance exception at $005D94B0. Exception class $C0000005 with message 'access violation at 0x005d94b0: write of address 0x00000004'. Process Plan2D.exe (1248)

Solution:
It turned out that the object I also called painter when I renamed it passed. It turns out in Delphi the class object cannot be called the class name.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kalapanga, 2016-05-31
@mergenich

And why did you decide that the error is in this constructor? Specifically, this ten lines does not cause any errors, the object is completely created for itself. Here the destructor is not enough for him, no one releases the sprite.

K
Konstantin Tsvetkov, 2017-08-25
@tsklab

Exception class $C0000005
This is a RAD Studio bug. It says it's been fixed .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question