W
weina
Unregistered / Unconfirmed
GUEST, unregistred user!
[red]为什么我已在保存对话框代码中设置了filter功能,可以保存为文本格式,却在保存后打开文件时还要选择打开方式???[/red]
代码如下:
procedure TFW210Form.Button2Click(Sender: TObject);
var
str: string;
filename: textfile;
n: integer;
p: string;
begin
inherited;
DM.importtable.SQL.Text := 'Select * from ' + RadioGroup1.Items.Strings[RadioGroup1.ItemIndex];
DM.importtable.Open;
try
SaveDialog1.Filter := 'Text File(*.txt)|*.txt';
if SaveDialog1.Execute then
begin
str := SaveDialog1.FileName;
Assignfile(FileName, str);
if FileExists(str) then DeleteFile(SaveDialog1.FileName);
Screen.Cursor := crHourGlass;
ReWrite(filename);
p := Combobox2.Text;
str := '';
DM.importtable.First;
for n := 0 to DM.querytemp.FieldCount - 1 do
begin
str := str + DM.importtable.fields[n].DisplayLabel + p;
end;
writeln(filename, str);
str := '';
while not DM.importtable.Eof do begin
for n := 0 to DM.importtable.FieldCount - 1 do
begin
str := str + DM.importtable.fields[n].AsString + p;
end;
Writeln(FileName, str);
str := '';
DM.importtable.Next;
end;
end;
Screen.Cursor := crdefault;
Closefile(filename);
MessageBox(0, '成功保存文件', '提示', MB_OK + MB_ICONINFORMATION);
except
Application.MessageBox('操作在没有警告的情况下正常结束!', '完成', mb_ok + mb_iconinformation);
end;
end;
代码如下:
procedure TFW210Form.Button2Click(Sender: TObject);
var
str: string;
filename: textfile;
n: integer;
p: string;
begin
inherited;
DM.importtable.SQL.Text := 'Select * from ' + RadioGroup1.Items.Strings[RadioGroup1.ItemIndex];
DM.importtable.Open;
try
SaveDialog1.Filter := 'Text File(*.txt)|*.txt';
if SaveDialog1.Execute then
begin
str := SaveDialog1.FileName;
Assignfile(FileName, str);
if FileExists(str) then DeleteFile(SaveDialog1.FileName);
Screen.Cursor := crHourGlass;
ReWrite(filename);
p := Combobox2.Text;
str := '';
DM.importtable.First;
for n := 0 to DM.querytemp.FieldCount - 1 do
begin
str := str + DM.importtable.fields[n].DisplayLabel + p;
end;
writeln(filename, str);
str := '';
while not DM.importtable.Eof do begin
for n := 0 to DM.importtable.FieldCount - 1 do
begin
str := str + DM.importtable.fields[n].AsString + p;
end;
Writeln(FileName, str);
str := '';
DM.importtable.Next;
end;
end;
Screen.Cursor := crdefault;
Closefile(filename);
MessageBox(0, '成功保存文件', '提示', MB_OK + MB_ICONINFORMATION);
except
Application.MessageBox('操作在没有警告的情况下正常结束!', '完成', mb_ok + mb_iconinformation);
end;
end;