第一个问题:删除Word文档出现的问题!代码如下:
procedure MoveFileToDustbin(Filename:string);
var
T:TSHFileOpStruct;
begin
FillChar(T,Sizeof(TSHFileOpStruct),#0);
with T do
begin
Wnd:=0;
wFunc:=FO_DELETE;
PFrom:=Pchar(Filename);
fFlags:=FOF_ALLOWUNDO; ///设定将文件删除到回收站中///
end;
SHFileOperation(T);{declared in ShellApI}
end;在过程中调用函数: MoveFileToDustbin(Template2);但有时可以删除到回收站中,有时提示如下错误:“无法删除文件:无法读源文件或磁盘”,待删除下一个Word文档时,有时又可以,有时却也不可以!请问是什么原因?如何解决?有代码最好!谢谢!
第二个问题:如何获得程序中Gauge1的Progress的值!
Application.CreateForm(Tscform,scform);
scform.Show;
scform.Caption:='正在进行数学建模......';
scform.Panel1.Caption:=scform.Caption;
application.ProcessMessages;
Randomize;
M:=20000000;
for i:=0 to M do
scform.gauge1.Progress:=(i) div (M div 100);
scform.Caption:='正在进行数据计算......';
scform.Panel1.Caption:=scform.Caption;
application.ProcessMessages;
for i:=0 to M do
scform.gauge1.Progress:=(i) div (M div 100);
scform.close;
scform.Release;
如何获得程序中Gauge1的Progress的值!比如将数据表中的数据插入到word中,如下所示!如何获得Gauge1的Progress的值!使其与插入数据的过程同步,当数据插入完毕,则进度条结束!用其他控间也可以,请提供相应代码!谢谢!!
vTable6 := WordApplication1.ActiveDocument.Tables.Item(6);
ADOQuery4.Close;
ADOQuery4.SQL.Clear;
ADOQuery4.SQL.Add('SELECT * FROM cz');
ADOQuery4.Open;
for i:=0 to ADOQuery4.RecordCount-1 do
begin
k1:=0;
k2:=0;
for j:=0 to 16 do
begin
vTable6.Cell(6, j+3).Range.Text:=ADOQuery4.Fields[j*2].AsString;
if trim(ADOQuery4.Fields[j*2].AsString)<>'' then
k1:=k1+ADOQuery4.Fields[j*2].value;
vTable6.Cell(7, j+3).Range.Text:=ADOQuery4.Fields[j*2+1].AsString;
if trim(ADOQuery4.Fields[j*2+1].AsString)<>'' then
k2:=k2+ADOQuery4.Fields[j*2+1].value;
end;
vTable6.Cell(6, 2).Range.Text:=inttostr(k1);
vTable6.Cell(7, 2).Range.Text:=inttostr(k2);
end;
procedure MoveFileToDustbin(Filename:string);
var
T:TSHFileOpStruct;
begin
FillChar(T,Sizeof(TSHFileOpStruct),#0);
with T do
begin
Wnd:=0;
wFunc:=FO_DELETE;
PFrom:=Pchar(Filename);
fFlags:=FOF_ALLOWUNDO; ///设定将文件删除到回收站中///
end;
SHFileOperation(T);{declared in ShellApI}
end;在过程中调用函数: MoveFileToDustbin(Template2);但有时可以删除到回收站中,有时提示如下错误:“无法删除文件:无法读源文件或磁盘”,待删除下一个Word文档时,有时又可以,有时却也不可以!请问是什么原因?如何解决?有代码最好!谢谢!
第二个问题:如何获得程序中Gauge1的Progress的值!
Application.CreateForm(Tscform,scform);
scform.Show;
scform.Caption:='正在进行数学建模......';
scform.Panel1.Caption:=scform.Caption;
application.ProcessMessages;
Randomize;
M:=20000000;
for i:=0 to M do
scform.gauge1.Progress:=(i) div (M div 100);
scform.Caption:='正在进行数据计算......';
scform.Panel1.Caption:=scform.Caption;
application.ProcessMessages;
for i:=0 to M do
scform.gauge1.Progress:=(i) div (M div 100);
scform.close;
scform.Release;
如何获得程序中Gauge1的Progress的值!比如将数据表中的数据插入到word中,如下所示!如何获得Gauge1的Progress的值!使其与插入数据的过程同步,当数据插入完毕,则进度条结束!用其他控间也可以,请提供相应代码!谢谢!!
vTable6 := WordApplication1.ActiveDocument.Tables.Item(6);
ADOQuery4.Close;
ADOQuery4.SQL.Clear;
ADOQuery4.SQL.Add('SELECT * FROM cz');
ADOQuery4.Open;
for i:=0 to ADOQuery4.RecordCount-1 do
begin
k1:=0;
k2:=0;
for j:=0 to 16 do
begin
vTable6.Cell(6, j+3).Range.Text:=ADOQuery4.Fields[j*2].AsString;
if trim(ADOQuery4.Fields[j*2].AsString)<>'' then
k1:=k1+ADOQuery4.Fields[j*2].value;
vTable6.Cell(7, j+3).Range.Text:=ADOQuery4.Fields[j*2+1].AsString;
if trim(ADOQuery4.Fields[j*2+1].AsString)<>'' then
k2:=k2+ADOQuery4.Fields[j*2+1].value;
end;
vTable6.Cell(6, 2).Range.Text:=inttostr(k1);
vTable6.Cell(7, 2).Range.Text:=inttostr(k2);
end;
2.showmessage( inttostr(Gauge1.Progress));取当前Gauge1.Progress,嘿嘿...
2、这是一个将数据导入到Excel表的,参考一下
begin VarExcel := CreateOleObject( 'Excel.Application' );
VarExcel.Workbooks.Add; if RB1.Checked then
begin
varnum := 3;
VarExcel.Cells[1,1].Value:='分';
VarExcel.Cells[1,2].Value:='数';
VarExcel.Cells[1,3].Value:='图';
VarExcel.Cells[1,4].Value:='金';
end
else if RB2.Checked then
begin
varnum := 3;
VarExcel.Cells[1,1].Value:='商';
VarExcel.Cells[1,2].Value:='数';
VarExcel.Cells[1,3].Value:='册';
VarExcel.Cells[1,4].Value:='额';
end
end; with frmDM.Clientdataset1 do
begin
First;
DisableControls;
FrmProgress := TFrmProgress.Create(nil);//创建一个进度条窗体。<br>
FrmProgress.Show;
FrmProgress.suiProgressBar1.Max := recordcount;
for VarI := 1 to (RecordCount) do
begin
for VarJ := 0 to Varnum do
begin
VarExcel.Cells[VarI + 1,VarJ+ 1].Value := Fields[VarJ].Text ;
end;
Next;
FrmProgress.suiProgressBar1.StepBy(1);
end;
end;
FrmProgress.Free;
if FileExists(VarFilePath) then
DeleteFile(VarFilePath);
VarExcel.ActiveSheet.SaveAs(VarFilePath);
VarExcel.ActiveWorkBook.Close;
VarExcel.Quit;
ShowMessage(VarFilePath + ',数据导出成功 ,');
frmDM.CDSOrderOther.EnableControls;
end;