刚学delphi就遇到问题,都看不懂,它显示错误:
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 004C14E5 in module 'Project1.exe'. Read of address 0000005C'. Process stopped. Use Step or Run to continue. 大家帮帮忙啊!
Project Project1.exe raised exception class EAccessViolation with message 'Access violation at address 004C14E5 in module 'Project1.exe'. Read of address 0000005C'. Process stopped. Use Step or Run to continue. 大家帮帮忙啊!
var
i:integer;
begin
ComboBox1.Items.Clear;
with DataModule7.ADOQuery1 do
begin
SQL.Clear;
SQL.Add('select Code from TL.TL.dbo.Book');
Open;
First;
for i:=0 to RecordCount-1 do
begin
ComboBox1.Items.Add(FieldbyName('Code').AsString);
Next;
end;
Close;
end;
end;
它指示地方为with DataModule7.ADOQuery1 do
EAccessViolation is the exception class for invalid memory access errors.EAccessViolation is raised when an applicationDereferences a nil (Delphi) or NULL (C++) pointer.
Writes to memory reserved for executable code.
Attempts to access a memory address for which there is no virtual memory allocated to the application.當引用一個空指針時報錯.即是最容易出現的'報地址錯';請看這段代碼:
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
//sender:=nil; //將指針設為空, 即它沒有指向任何對象.
//sender.free; //或將這個對象釋放
showmessage(sender.ClassName); //設置上面任何一行代碼就會引發這個异常
end;
Application.Initialize; Application.CreateForm(TDataModule7, DataModule7); //有了這行就可以了 Application.CreateForm(TForm1, Form1);
Application.Run;
end.