龙
龙之天涯
Unregistered / Unconfirmed
GUEST, unregistred user!
下面一个函数是用来从一个文本文件中读取数据,采用了缓存模式
但是问题在出异常了以后还是将记录给提交了,
我就想在发生异常得时候一条记录都不提交应该如何修改??
function TFormsjzr.sjzr(filename:string;Tstr:tstringList;table:ToraTable;len:integer;sep:string;Tip:string):boolean;
var
j:integer;
str:string;
postion:integer;
myexception: exception;
begin
if (i < Tstr.Count) and (copy(Tstr.Strings,
length(Tstr.Strings) - len, len+1) = sep) then
begin
table.close;
table.Prepare ;
table.open;
end;
while (i < Tstr.Count) and (copy(Tstr.Strings,length(Tstr.Strings) - len, len+1) = sep) do
begin
try
j := 0;
table.insert;
str := Tstr.Strings;
while (j < table.fieldcount - 1) do
begin
postion := pos(',', str);
if j = table.fieldcount - 2 then
begin
if postion <> 1 then
table.fields[j].value := copy(str, 1, postion - 1)
else
table.fields[j].value := null;
end
else if postion <> 1 then
table.fields[j].value := copy(str, 1, postion - 1)
else
table.fields[j].value := null;
str := copy(str, postion + 1, (length(str) - postion));
j := j + 1;
end; //end while
table.post;
i := i + 1;
StatusBarmsg.Panels[0].text :='正在处理:'+FileName;
StatusBarmsg.Panels[1].text := '已处理' + inttostr(i) + '条记录,总共有'
+ inttostr(Tstr.Count) + '条记录';
FormMain.RxTrayIcon1.Hint:=Tip+inttostr(i)+'条记录,总共有'+inttostr(Tstr.Count) + '条记录';
FormMain.Refresh ;
Formsjzr.Refresh;
except
on e:exception do
begin
edtbaodan.Lines.add(pchar('错误原因如下:'+chr(13)+convert_error_message(e.message)));
edtbaodan.Lines.Add('文件:'+FileName+Tstr.Strings+'该条报单记录出错,请重新核对!');
table.CancelUpdates ;
i := i + 1;
transflag:=true;
continue;
end;
end;
table.ApplyUpdates ;
end;
end;
但是问题在出异常了以后还是将记录给提交了,
我就想在发生异常得时候一条记录都不提交应该如何修改??
function TFormsjzr.sjzr(filename:string;Tstr:tstringList;table:ToraTable;len:integer;sep:string;Tip:string):boolean;
var
j:integer;
str:string;
postion:integer;
myexception: exception;
begin
if (i < Tstr.Count) and (copy(Tstr.Strings,
length(Tstr.Strings) - len, len+1) = sep) then
begin
table.close;
table.Prepare ;
table.open;
end;
while (i < Tstr.Count) and (copy(Tstr.Strings,length(Tstr.Strings) - len, len+1) = sep) do
begin
try
j := 0;
table.insert;
str := Tstr.Strings;
while (j < table.fieldcount - 1) do
begin
postion := pos(',', str);
if j = table.fieldcount - 2 then
begin
if postion <> 1 then
table.fields[j].value := copy(str, 1, postion - 1)
else
table.fields[j].value := null;
end
else if postion <> 1 then
table.fields[j].value := copy(str, 1, postion - 1)
else
table.fields[j].value := null;
str := copy(str, postion + 1, (length(str) - postion));
j := j + 1;
end; //end while
table.post;
i := i + 1;
StatusBarmsg.Panels[0].text :='正在处理:'+FileName;
StatusBarmsg.Panels[1].text := '已处理' + inttostr(i) + '条记录,总共有'
+ inttostr(Tstr.Count) + '条记录';
FormMain.RxTrayIcon1.Hint:=Tip+inttostr(i)+'条记录,总共有'+inttostr(Tstr.Count) + '条记录';
FormMain.Refresh ;
Formsjzr.Refresh;
except
on e:exception do
begin
edtbaodan.Lines.add(pchar('错误原因如下:'+chr(13)+convert_error_message(e.message)));
edtbaodan.Lines.Add('文件:'+FileName+Tstr.Strings+'该条报单记录出错,请重新核对!');
table.CancelUpdates ;
i := i + 1;
transflag:=true;
continue;
end;
end;
table.ApplyUpdates ;
end;
end;