procedure TForm_Kinds.FormCreate(Sender: TObject); var a:integer; begin for a:=1 to Form1.ADOTable1.RecordCount do begin ListBox1.Items[a-1]:='xyz'; end; end;
什么时候用的?这段代码最好不能放在FormCreate()
但程序执行到 for a:=1 to Form1.ADOTable1.RecordCount do 就出错, 错误信息为:access violation at address 004cc3d5 in module 'project1.exe' read of address ffffff
Form1是哪来的?开始创建了吗?
哦,打错了,是 procedure TForm_Kinds.FormCreate(Sender: TObject); var a:integer; begin for a:=1 to Form_Kinds.ADOTable1.RecordCount do begin ListBox1.Items[a-1]:='xyz'; end; end;
recordcount 就是有问题,如果要得到记录数,你可以: var i:integer; with query1 do begin close; requestlive:=false; sql.clear; sql.add(' select count(*) from table1 '); open; i:=fields[0].asintger; end; i的值就是该表的记录数
你的ADOTable1 控件在 Form_Kinds 上是不能这么用的控件还没创建当然会出 access violation at address 004cc3d5 in module 'project1.exe' read of address ffffff 的错误。 如果一定要这么用,再建立一个 DataModul 把ADOTable1 放在那里,将其创建语句放在Form_Kinds 创建前就可以了。
var a:integer;
begin
for a:=1 to Form1.ADOTable1.RecordCount do
begin
ListBox1.Items[a-1]:='xyz';
end;
end;
错误信息为:access violation at address 004cc3d5 in module 'project1.exe' read of address ffffff
procedure TForm_Kinds.FormCreate(Sender: TObject);
var a:integer;
begin
for a:=1 to Form_Kinds.ADOTable1.RecordCount do
begin
ListBox1.Items[a-1]:='xyz';
end;
end;
var
i:integer;
with query1 do
begin
close;
requestlive:=false;
sql.clear;
sql.add(' select count(*) from table1 ');
open;
i:=fields[0].asintger;
end;
i的值就是该表的记录数
access violation at address 004cc3d5 in module 'project1.exe' read of address ffffff
的错误。
如果一定要这么用,再建立一个 DataModul 把ADOTable1 放在那里,将其创建语句放在Form_Kinds 创建前就可以了。