Delphi: inherited Create gives Access violation

611 views Asked by At

I made an application that opens several other Forms for handling tasks. All forms work fine, except one. I am using the same code for all forms. It's like:

FormTypeA := TFormTypeA.Create(Application);

In the Create constructor I added some code to initialize the form. It contains lines like:

constructor TFormTypeA.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  more code ...
end;

On the line "inherited Create(AOwner);" I get an Access violation: "Project ThisApplication.exe raised exception class $C0000005 with message 'c0000005 ACCESS_VIOLATION'

I simply don't have a clue where to look in my code to tackle the problem. As I wrote, other forms use the same structure and work fine.

Any suggestion would be very welcome.

1

There are 1 answers

0
cvz On

Ok. This is what happened.

While designing this specific Form I make use of several TGridPanels. These panels consists of Columns and Rows. The cells that are created by this grid, can be filled with VCL-objects. As soon as you drop these objects on the form, you have to draw them to the desired GridPanel. After that you have to specify the correct cell by typing the desired row and column in the object inspector.

So far so good.

As soon as you make up your mind and want to change the cell position of some object, this way of working becomes less structured. Objects shift to a next position, but that's not always free, so they shift too and so things get cluttered soon.

To avoid this you can work in the Text version of the form. How? Right click on the Form and choose View as Text. Go to the right spot and make the corrections. When you're done, Right Click again and choose View as Form.

There is a risk of this way of working, and that's: Typo's

Many will be caught by the compiler, but not this one:

ControlCollection = <
  item
    Column = 0
    Control = SomeControlA
    Row = 0
  end
  item
    Column = -1  <------ Fatal!
    Row = 0
  end
  item
    Column = 0
    Control = SomeControlB
  end
end>

The fatal line is the negative value for the Column (or Row). That's obvious. There is no negative columnnumber. That's what happens when you write code.

If you turn back to the form, you get no error or warning. When compiling? Silence. But Running? "exception class $C0000005 with message 'c0000005 ACCESS_VIOLATION"

I know, everybody makes typo's. This one is nasty.

It took me quite some time to find this out. I hope this description will help others.