救我啊,这么离谱

goease 2002-05-12 07:47:44
我在一个比较长的函数锂,有一个循环,当我结束循环的时候,内存会报错,这个是什么原因呀? 好像说的是我数据模型里出错阿,再有, 不知道adoquery使用的时候要注意些什么吗? 我是用它来插入数据到表中的,不过报错好像很奇怪,偏偏到循环结束的时候才发生
...全文
31 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
goease 2002-05-13
  • 打赏
  • 举报
回复
是string的数组,有问题吗?
szdino 2002-05-12
  • 打赏
  • 举报
回复
tempstr是个pchar还是string?
goease 2002-05-12
  • 打赏
  • 举报
回复
顶一下
zhptj 2002-05-12
  • 打赏
  • 举报
回复
gz
goease 2002-05-12
  • 打赏
  • 举报
回复
好啊


for l:=1 to cycle do //这里出错,如果cycle是3,当l:=4时
begin
setlength(tempstr,cycle*num);
j:=0;
ssql:='insert into sc_route_shift values(:tename,:grname,:shname';
si:=0;
while j<n do
begin
if si<cycle*num then
begin
ynum:=0;
nnum:=0;
ypos:=0;
npos:=0;
if shift_array[j]=l then
begin
sc.comp_ADOQuery1.Active:=false;
sc.comp_ADOQuery1.SQL.Clear;
sc.comp_ADOQuery1.SQL.Add('select route_train1,route_train2,start_time1,arrive_time1,');
sc.comp_ADOQuery1.SQL.Add('start_time2,arrive_time2 from sc_little_route');
sc.comp_ADOQuery1.SQL.Add('where route_id=:routeid');
sc.comp_ADOQuery1.Parameters.ParamByName('routeid').value:=route_array[j];
sc.comp_ADOQuery1.Active:=true;
for k:=0 to 5 do
string_array[k]:=sc.comp_ADOQuery1.Fields.Fields[k].Text;
for k:=2 to 5 do
begin
ypos:=pos('Y',string_array[k]);
npos:=pos('N',string_array[k]);
if ypos<>0 then
ynum:=ynum+1;
if npos<>0 then
nnum:=nnum+1;
end;
if ynum=2 then
begin
si:=day[j]-1;
tempstr[si]:=copy(string_array[0],0,4);
tempstr[si+1]:=copy(string_array[1],0,4);
j:=j+3;
end
else if ynum=1 then
begin
si:=day[j]-1;
tempstr[si]:=copy(string_array[0],0,4)+'/'+copy(string_array[1],0,4);
j:=j+1;
end
else if nnum=1 then
begin
si:=day[j]-1;
tempstr[si]:=copy(string_array[0],0,4)+'/'+copy(string_array[1],0,4);
if si=cycle*num-1 then
tempstr[0]:='到'
else
tempstr[si+1]:='到';
j:=j+2;
end
else
begin
si:=day[j];
tempstr[si]:=copy(string_array[0],0,4)+'/'+copy(string_array[1],0,4);
j:=j+1;
end;
end
else
j:=j+1;
end
else
break;
end;
for j:=0 to cycle*num-1 do
begin
if tempstr[j]='' then
tempstr[j]:='休息';
end;
for j:=0 to 15 do
begin
if j<cycle*num then
ssql:=ssql+','+''''+tempstr[j]+''''
else
ssql:=ssql+','+'''''';
end;
ssql:=ssql+')';
sc.comp_ADOQuery1.Active:=false;
sc.comp_ADOQuery1.SQL.Clear;
sc.comp_ADOQuery1.SQL.Add(ssql);
sc.comp_ADOQuery1.Parameters.ParamByName('tename').value:=teamname;
sc.comp_ADOQuery1.Parameters.ParamByName('grname').value:=groupname;
sc.comp_ADOQuery1.Parameters.ParamByName('shname').value:=inttostr(l);
sc.comp_ADOQuery1.ExecSQL;
ssql:='';
setlength(tempstr,0);
end;

其他要定义的我都定义了,而且插入数据也有的
szdino 2002-05-12
  • 打赏
  • 举报
回复
贴出你的source。
循环结束才出错,这可能delphi结束这个函数的时候,释放资源出错。
huier22 2002-05-12
  • 打赏
  • 举报
回复
关注

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧