Z
zhuzi
Unregistered / Unconfirmed
GUEST, unregistred user!
我写的一个DELPHI函数可是每次运行到Tmpparam2.Free;时就会报错,不知为什么,难道TPARAM不
需要释放吗?请高手帮我解决!去掉我注释的那三行程序就不会报错,可加上就会出错。
function InsertTMPRKTM(TmpStr1,TmpStr2,TmpStr3,TmpStr4:string):integer;
var
TmpParam1,TmpParam2,TmpParam3,TmpParam4:TParam;
begin
try
TelxonQuery:=TQuery.Create(nil);
with TelxonQuery do
begin
DatabaseName :=TelxonDatabase.DatabaseName ;
SessionName :=TelxonSession.SessionName ;
if active then close;
Params.Clear ;
TmpParam1:=TParam.Create(Params,ptInput);
TmpParam2:=TParam.Create(Params,ptInput);
TmpParam3:=TParam.Create(Params,ptInput);
TmpParam4:=TParam.Create(Params,ptInput);
try
Params[0].Name:='NewRuKuDan';
Params[0].ParamType :=ptInput;
ParamByName('NewRuKuDan').AsString:=TmpStr1;
Params[1].Name:='Newbox';
Params[1].ParamType :=ptInput;
ParamByName('Newbox').AsString:=TmpStr3;
Params[2].Name:='newshangpin';
Params[2].ParamType :=ptInput;
ParamByName('NewShangPin').AsString:=TmpStr4;
Params[3].Name:='Newcolor';
Params[3].ParamType :=ptInput;
ParamByName('Newcolor').AsString:=TmpStr2;
sql.Clear;
sql.Add('INSERT INTO TMPRKTM (rkdjh, hwtm, hwxftm, hwsx) VALUES NewRukuDan,:NewBox,:NewShangPin,:NewColor)');
prepare;
execsql;
Close;
unprepare;
finally
TmpParam1.free;
// Tmpparam2.Free;
// TmpParam3.free;
// Tmpparam4.Free;
Free;
end;
end;
except
on E: Exception do writeln(E.Message);
end;
end;
需要释放吗?请高手帮我解决!去掉我注释的那三行程序就不会报错,可加上就会出错。
function InsertTMPRKTM(TmpStr1,TmpStr2,TmpStr3,TmpStr4:string):integer;
var
TmpParam1,TmpParam2,TmpParam3,TmpParam4:TParam;
begin
try
TelxonQuery:=TQuery.Create(nil);
with TelxonQuery do
begin
DatabaseName :=TelxonDatabase.DatabaseName ;
SessionName :=TelxonSession.SessionName ;
if active then close;
Params.Clear ;
TmpParam1:=TParam.Create(Params,ptInput);
TmpParam2:=TParam.Create(Params,ptInput);
TmpParam3:=TParam.Create(Params,ptInput);
TmpParam4:=TParam.Create(Params,ptInput);
try
Params[0].Name:='NewRuKuDan';
Params[0].ParamType :=ptInput;
ParamByName('NewRuKuDan').AsString:=TmpStr1;
Params[1].Name:='Newbox';
Params[1].ParamType :=ptInput;
ParamByName('Newbox').AsString:=TmpStr3;
Params[2].Name:='newshangpin';
Params[2].ParamType :=ptInput;
ParamByName('NewShangPin').AsString:=TmpStr4;
Params[3].Name:='Newcolor';
Params[3].ParamType :=ptInput;
ParamByName('Newcolor').AsString:=TmpStr2;
sql.Clear;
sql.Add('INSERT INTO TMPRKTM (rkdjh, hwtm, hwxftm, hwsx) VALUES NewRukuDan,:NewBox,:NewShangPin,:NewColor)');
prepare;
execsql;
Close;
unprepare;
finally
TmpParam1.free;
// Tmpparam2.Free;
// TmpParam3.free;
// Tmpparam4.Free;
Free;
end;
end;
except
on E: Exception do writeln(E.Message);
end;
end;