delphi access violation
Greetings
the following code gives a error:
"Project prKlanten.exe reaised exception class EAccessviolation with message 'acces violation at address 004d7767 in module 'prKlanten.exe'.
Read of address 0000005C."
procedure TfmOrder.FormCreate(Sender: TObject);
begin
dm.atDier开发者_运维技巧.Open;
while not dm.atDier.eof do
begin
cbKeuze.Items.Add(dm.atDier['Diernaam']);
dm.atDier.Next
end;
dm.atDier.Close;
end;
Anyone know why? If you need more information feel free to ask.
[edit]
For more information see jasper's post
I bet that dm
hasn't been created yet.
I bet that cbKeuse.Items
hasn't been created yet.
I bet that dm
hasn't been created yet.
Change this bit and run again:
[snip]
begin
Assert(dm<>nil);
Assert(dm.atDier<>nil);
dm.atDier.Open;
while not dm.atDier.eof do
[snip]
Do the assertions pass?
Access violations are caused when you access memory that is not yours such as:
- using a nil pointer
- buffer overrun
- accessing an uninitialized pointer/object
- accessing a freed pointer/object
Possible sources of access violations (or illegal/uninitialized pointers):
- dm is not set
- dm.atDier is not set
- cbKeuze is not set
- dm.atDier['Diernaam'] fails
In order to give more help, we need to known which line caused the access violation.
Addition Does the AV also happens if you move the code to a temporary OnClick of a temporary button? In other words, remove the code from the OnCreate as you can't be 100% sure the dm is fully operational. The OnActivate is another possibility, but you need to check for second activation.
精彩评论