内存非法访问
re.free出现内存非法访问的错误,请教各位高手!
var
ii,j:integer ;
deletechart:string;
queryc:TADOQuery;
begin
try
queryc:=TADOQuery.Create(self);
queryc.Connection :=dbprocess.acprocess ;
for ii:=FrmMain.ComponentCount-1 downto 0 do
begin
if FrmMain.Components[ii] is TRectBox then
begin
re:=TRectBox(FrmMain.Components[ii]);
deletechart:=FrmMain.Components[ii].Name;
with queryc do
begin
if midstr(deletechart,1,3)= 'Uob ' then /////////////删除活动图信息
begin
if re.Focus then
begin
close;
sql.Clear ;
sql.Text := 'select * from uob where uob_id= ' ' '+deletechart+ ' ' 'and model_id= ' ' '+model_id+ ' ' ' ';
open;
if recordcount=0 then
begin
combobox1.Items.Delete(combobox1.Items.IndexOf(re.Name));
combobox1.text:= ' ';
VLE.Strings.Clear;
for j:=0 to treeview1.Items.Count-1 do
begin
if treeview1.Items[j].Text=re.Caption then
begin
treeview1.Items.Delete(treeview1.Items[j]);
break;
end;
end;
re.Free;
re:=nil;
break;
end
[解决办法]
把代码弄规范一点,这么乱, 怎么看啊。
[解决办法]
var
ii,j: Integer ;
deletechart: String;
queryc: TADOQuery;
begin
try
queryc := TADOQuery.Create(self);
queryc.Connection := dbprocess.acprocess ;
for ii := FrmMain.Component Count-1 down to 0 do
begin
if FrmMain.Components[ii] is TRectBox then
begin
re := TRectBox(FrmMain.Components[ii]);
deletechart := FrmMain.Components[ii].Name;
with queryc do
begin
if midstr(deletechart,1,3) = 'Uob ' then /////////////删除活动图信息
begin
if re.Focus then
begin
close;
sql.Clear ;
sql.Text := 'select * from uob where uob_id= ' ' '+deletechart+ ' ' '
and model_id= ' ' '+model_id+ ' ' ' ';
open;
if recordcount=0 then
begin
combobox1.Items.Delete(combobox1.Items.IndexOf(re.Name));
combobox1.text:= ' ';
VLE.Strings.Clear;
for j:=0 to treeview1.Items.Count-1 do
begin
if treeview1.Items[j].Text=re.Caption then
begin
treeview1.Items.Delete(treeview1.Items[j]);
break;
end;
end;
re.Free;
re:=nil;
break;
end
没做什么事,就是看你代码太乱了,帮你整整
[解决办法]
re是啥,定义在哪呢?