📄 waitpas_unit.pas
字号:
{数据备份、还原}
unit WaitPas_Unit;
interface
uses
Classes, windows, SysUtils,Forms,ADODB,Dialogs,Variants,ActiveX,ComObj,ComCtrls;
type
WaitPas = class(TThread)
Filename : String; //往线程中注入备份或还原的文件名
Messages : String; //显示信息
IDs : Integer; //识别应该执行什么样的操作
//打开Excel
function OpenExcel: Boolean;
function ReadExcel: Boolean;
//关闭等待窗口
procedure CloseWaitWindow;
//更新等待窗口信息
procedure PostMessgesToWaitWindow;
private
{ Private declarations }
protected
procedure Execute; override;
public
constructor Create(FileNames:String;LoadID:integer);
end;
implementation
uses Wait, DrawInfor, GlobalVarDefs;
{ WaitPas }
Function WaitPas.OpenExcel:Boolean;
var
i:Integer;
begin
Messages:='正在打开Excel表格,请稍候……';
Synchronize(PostMessgesToWaitWindow);
try
try
Excel:=CreateOleObject('Excel.Application' );
except
on Exception do raise exception.Create('无法创建Xls文件,请确认是否安装EXCEL')
end;
with DrawInforForm do begin
Excel.Workbooks.Open(OpenDialog1.FileName);
//**********
ComboBox1.Clear;
For i:=1 to Excel.Worksheets.Count do
ComboBox1.Items.Add(Excel.Worksheets.Item[i].Name);
ComboBox1.ItemIndex:=0;
// Excel.Visible := True;
Edit1.Text:=OpenDialog1.FileName;
Excel.ActiveWorkBook.Saved := True; //表示不保存,关闭,不再显示是否保存的消息,而是直接关闭
// sleep(1000);//wait
End;
Result:=true;
except
Result:=false;
end;
end;
//读取Excel
Function WaitPas.ReadExcel:Boolean;
var
i,j : Integer;
Item : TListItem;
begin
Messages:='正在读取Excel表格,请稍候……';
Synchronize(PostMessgesToWaitWindow);
with DrawInforForm do begin
lvTestPointList.Clear;
ProgressBar1.Position:=0;
try
ProgressBar1.Max := Excel.ActiveSheet.UsedRange.Rows.Count-1;
if Excel.ActiveSheet.UsedRange.Rows.Count > updown1.Position then
begin
for i:=updown1.Position to (Excel.ActiveSheet.UsedRange.Rows.Count) do
begin
Item := lvTestPointList.Items.Add;
Item.Caption :=IntToStr(lvTestPointList.Items.Count);
for j:=updown2.Position to 2 do
Item.SubItems.Add(Excel.Cells.Item[i,j]);
ProgressBar1.Position:=i-1;
end;
end;
except;
Result:=True;
end;
Result:=false;
end;
end;
procedure WaitPas.CloseWaitWindow;
begin
WaitForm.Close;
end;
constructor WaitPas.Create(FileNames: String; LoadID: Integer);
begin
//初始化进程
IDs := LoadID;
FileName := FileNames;
inherited Create(False);
end;
procedure WaitPas.Execute;
var IsSucceed : Boolean;
begin
IsSucceed:=false;
CoInitialize(nil);
case IDs of
1 : IsSucceed := OpenExcel ; //打开Excel
2 : IsSucceed := ReadExcel ; //读取Excel
end;
Synchronize(CloseWaitWindow);
if IsSucceed then
// Messagebox(0,'本次操作成功!','提示',MB_OK+MB_ICONINFORMATION+MB_TOPMOST)
else
begin
Messagebox(0,'操作失败,请稍后再试!','提示',MB_OK+MB_ICONINFORMATION+MB_TOPMOST);
end;
{ Place thread code here }
end;
procedure WaitPas.PostMessgesToWaitWindow;
begin
WaitForm.RzLabel1.Caption:=Messages;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -