请教!
我的保存对话框为什么如果取消,就是说一出现对话框后,取消不保存就会出错?
出错位置在倒数第四行,大家帮看看,谢.
procedure TMainForm.Button1Click(Sender: TObject);
var
i,j:integer;
TempString:string;
StringList:TStringList;
begin
//导出文件 if trim(ComboBox1.Text)='' then
begin
ShowMessage('请选择导出的文件类型');
Abort;
end; if trim(ComboBox1.Text)='文本文件' then
begin
//导出文本
StringList:=TStringList.Create;
TempString:='| ';
AdoTable1.First;
While not AdoTable1.Eof do
begin
for i:=0 to AdoTable1.RecordCount-1 do
begin
for j:=0 to AdoTable1.FieldCount-1 do
begin
TempString:=TempString+AdoTable1.Fields[j].AsString+'| ';
end;
StringList.Add(TempString);
TempString:='| ';
AdoTable1.Next;
end;
end; with Savedialog1 do
begin
saveDialog1.DefaultExt:='*.txt';
saveDialog1.Filter:='文本文件(*.txt)|*.txt';
ExeCute;
StringList.SaveToFile(saveDialog1.FileName);
end;
StringList.Clear; //出错的句子,提示StringList为空错误,如何改?
TempString:=''; end;
end;
我的保存对话框为什么如果取消,就是说一出现对话框后,取消不保存就会出错?
出错位置在倒数第四行,大家帮看看,谢.
procedure TMainForm.Button1Click(Sender: TObject);
var
i,j:integer;
TempString:string;
StringList:TStringList;
begin
//导出文件 if trim(ComboBox1.Text)='' then
begin
ShowMessage('请选择导出的文件类型');
Abort;
end; if trim(ComboBox1.Text)='文本文件' then
begin
//导出文本
StringList:=TStringList.Create;
TempString:='| ';
AdoTable1.First;
While not AdoTable1.Eof do
begin
for i:=0 to AdoTable1.RecordCount-1 do
begin
for j:=0 to AdoTable1.FieldCount-1 do
begin
TempString:=TempString+AdoTable1.Fields[j].AsString+'| ';
end;
StringList.Add(TempString);
TempString:='| ';
AdoTable1.Next;
end;
end; with Savedialog1 do
begin
saveDialog1.DefaultExt:='*.txt';
saveDialog1.Filter:='文本文件(*.txt)|*.txt';
ExeCute;
StringList.SaveToFile(saveDialog1.FileName);
end;
StringList.Clear; //出错的句子,提示StringList为空错误,如何改?
TempString:=''; end;
end;
StringList.SaveToFile(saveDialog1.FileName);
改成:
if ExeCute then
StringList.SaveToFile(saveDialog1.FileName);
StringList.SaveToFile(saveDialog1.FileName)
else
showmessage('你怎么点了cancel ???');
exit;
StringList.SaveToFile(saveDialog1.FileName)