我的用法如下,用到了该控件包的TZip和TUnZip控件:
procedure TFrm_SaveRecipe.Btn_ImportDataClick(Sender: TObject);
var
temppath:string;
begin
//数据导入
TempPath := ExtractFilePath(Application.ExeName) + 'Bak/';
if Copy(TempPath,Length(TempPath),1) <> '/' then
TempPath := TempPath + '/';
if not DirectoryExists(TempPath) then
ForceDirectories(TempPath);
OpenDlg_Recipe.FileName := '自建处方';
OpenDlg_Recipe.InitialDir := TempPath;
if OpenDlg_Recipe.Execute then
begin
unzip1.ArchiveFile := OpenDlg_Recipe.FileName;
unzip1.FileSpec.Clear;
unzip1.FileSpec.Add('*.*');//这里是默认全部文件,也应该可以用: 'temp.txt'指定某一个文件
unzip1.ExtractDir := temppath;
if unzip1.Extract > 0 then
begin
try
try
Do_ADOSQL(dm.Con_JiuQ,'drop table 自建处方');
Do_ADOSQL(DM.Con_JiuQ,'Select * Into 自建处方 From [Text;Database=' + temppath + '].temp.txt');
showmessage('[自建处方]库已经成功导入!');
except
showmessage('[自建处方]库导入失败!');
end;
finally
DeleteFile(temppath + 'temp.txt');
DeleteFile(temppath + 'schema.ini');
end;
end
else
Showmessage('[自建处方]库导入失败!');
end;
end;
procedure TFrm_SaveRecipe.Btn_ExportDataClick(Sender: TObject);
var
TempPath : string;
begin
inherited;
//数据导出
TempPath := ExtractFilePath(Application.ExeName) + 'Bak/';
if Copy(TempPath,Length(TempPath),1) <> '/' then
TempPath := TempPath + '/';
if not DirectoryExists(TempPath) then
ForceDirectories(TempPath);
SaveDlg_Recipe.FileName := '自建处方';
SaveDlg_Recipe.InitialDir := TempPath;
if SaveDlg_Recipe.Execute then
begin
if FileExists(TempPath + 'temp.txt') then
DeleteFile(TempPath + 'temp.txt');
if FileExists(TempPath + ExtractFileName(SaveDlg_Recipe.FileName)) then
DeleteFile(TempPath + ExtractFileName(SaveDlg_Recipe.FileName));
Do_ADOSQL(dm.Con_JiuQ,'Select * Into [Text;Database=' + temppath + '].temp.txt From 自建处方');
try
zip1.ArchiveFile := SaveDlg_Recipe.FileName;
Zip1.FileSpec.Clear;
Zip1.FileSpec.Add(TempPath + 'temp.txt'); //如果要压缩指定目录下全部文件,可以用 tempPath + '*.*'
if Zip1.Compress > 0 then
showmessage('自建处方库导出成功!' + #13#10#13#10 + '存放路径及文件名:' + SaveDlg_Recipe.FileName,4)
else
showmessage('自建处方库导出失败!',4);
finally
DeleteFile(TempPath + 'temp.txt');
DeleteFile(TempPath + 'schema.ini');
end;
end;
end;
可以去网上找该控件,也可以留下Email,我发给你