| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 845 人关注过本帖
标题:重金求解:ado多线程问题
只看楼主 加入收藏
wklhdt
Rank: 1
等 级:新手上路
帖 子:45
专家分:0
注 册:2006-5-23
收藏
 问题点数:0 回复次数:0 
重金求解:ado多线程问题

小弟遇一问题,为什么在执行线程时,只复制了一个表,而后面的代码不执行?
代码如下:
这是线程那个单元
unit Unit2;

interface
uses
Classes,unit1, Windows, Messages, SysUtils, Variants, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, DB, ADODB, ComCtrls,comobj,excel2000,Activex;

type
mythread = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
end;

implementation

{ Important: Methods and properties of objects in VCL or CLX can only be used
in a method called using Synchronize, for example,

Synchronize(UpdateCaption);

and UpdateCaption could look like,

procedure mythread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end; }

{ mythread }

procedure mythread.Execute;

var
xlApp, xlBook, xlSheet,xlQuery: Variant;
filename : string;
begin
CoInitialize(nil);
form1.button1.Enabled:=false;
form1.savedialog1.FileName:='文化路'+datetostr(date);
form1.savedialog1.Execute;
filename:=form1.savedialog1.FileName;
if filename='' then
begin
exit;
end;
form1.adodataset1.Close;
form1.adodataset1.CommandText:='select * from 文化路_c';
form1.adodataset1.Open;
if form1.adodataset1.IsEmpty then
begin
showmessage('没有数据可以导出!');
exit;
end;
xlApp := CreateOleObject('Excel.Application');
xlBook := xlApp.Workbooks.Add;
xlSheet := xlBook.Worksheets['sheet1'];
xlApp.Visible := false;
xlQuery := xlSheet.QueryTables.Add(form1.adodataset1.Recordset ,xlSheet.Range['A1']);
xlQuery.FieldNames := true;
xlQuery.RowNumbers := False;
xlQuery.FillAdjacentFormulas := False;
xlQuery.PreserveFormatting := True;
xlQuery.RefreshOnFileOpen := False;
xlQuery.BackgroundQuery := True;
xlQuery.RefreshStyle := xlOverwriteCells;
xlQuery.SaveData := True;
xlQuery.AdjustColumnWidth := True;
xlQuery.RefreshPeriod := 0;
xlQuery.PreserveColumnInfo := True;
xlQuery.Refresh;
xlapp.DisplayAlerts:=false;
xlapp.Workbooks[1].SaveAs(filename);
xlapp.quit;
xlApp := Unassigned;
xlBook := Unassigned;
form1.progressbar1.Position:=25;
CoUninitialize;

if FileExists(filename) then
begin
CoInitialize(nil);
form1.adodataset1.Close;
form1.adodataset1.CommandText:='select * from 大同路_c';
form1.adodataset1.Open;
filename:=stringreplace(filename,'文化路','大同路',[rfReplaceAll]) ;
if form1.adodataset1.IsEmpty then
begin
showmessage('没有数据可以导出!');
exit;
end;
xlApp := CreateOleObject('Excel.Application');
xlBook := xlApp.Workbooks.Add;
xlSheet := xlBook.Worksheets['sheet1'];
xlApp.Visible := false;
xlQuery := xlSheet.QueryTables.Add(form1.adodataset1.Recordset ,xlSheet.Range['A1']);
xlQuery.FieldNames := true;
xlQuery.RowNumbers := False;
xlQuery.FillAdjacentFormulas := False;
xlQuery.PreserveFormatting := True;
xlQuery.RefreshOnFileOpen := False;
xlQuery.BackgroundQuery := True;
xlQuery.RefreshStyle := xlOverwriteCells;
xlQuery.SaveData := True;
xlQuery.AdjustColumnWidth := True;
xlQuery.RefreshPeriod := 0;
xlQuery.PreserveColumnInfo := True;
xlQuery.Refresh;
xlapp.DisplayAlerts:=false;
xlapp.Workbooks[1].SaveAs(filename);
xlapp.quit;
xlApp := Unassigned;
xlBook := Unassigned;
form1.progressbar1.Position:=50;
end;

if FileExists(filename) then
begin
form1.adodataset1.Close;
form1.adodataset1.CommandText:='select * from 政一街e';
form1.adodataset1.Open;
filename:=stringreplace(filename,'大同路','政一街',[rfReplaceAll]) ;
if form1.adodataset1.IsEmpty then
begin
showmessage('没有数据可以导出!');
exit;
end;
xlApp := CreateOleObject('Excel.Application');
xlBook := xlApp.Workbooks.Add;
xlSheet := xlBook.Worksheets['sheet1'];
xlApp.Visible := false;
xlQuery := xlSheet.QueryTables.Add(form1.adodataset1.Recordset ,xlSheet.Range['A1']);
xlQuery.FieldNames := true;
xlQuery.RowNumbers := False;
xlQuery.FillAdjacentFormulas := False;
xlQuery.PreserveFormatting := True;
xlQuery.RefreshOnFileOpen := False;
xlQuery.BackgroundQuery := True;
xlQuery.RefreshStyle := xlOverwriteCells;
xlQuery.SaveData := True;
xlQuery.AdjustColumnWidth := True;
xlQuery.RefreshPeriod := 0;
xlQuery.PreserveColumnInfo := True;
xlQuery.Refresh;
xlapp.DisplayAlerts:=false;
xlapp.Workbooks[1].SaveAs(filename);
xlapp.quit;
xlApp := Unassigned;
xlBook := Unassigned;
form1.progressbar1.Position:=75;
end;
if FileExists(filename) then
begin
form1.adodataset1.Close;
form1.adodataset1.CommandText:='select * from 集团用户';
form1.adodataset1.Open;
filename:=stringreplace(filename,'政一街','集团用户',[rfReplaceAll]) ;
if form1.adodataset1.IsEmpty then
begin
showmessage('没有数据可以导出!');
exit;
end;
xlApp := CreateOleObject('Excel.Application');
xlBook := xlApp.Workbooks.Add;
xlSheet := xlBook.Worksheets['sheet1'];
xlApp.Visible := false;
xlQuery := xlSheet.QueryTables.Add(form1.adodataset1.Recordset ,xlSheet.Range['A1']);
xlQuery.FieldNames := true;
xlQuery.RowNumbers := False;
xlQuery.FillAdjacentFormulas := False;
xlQuery.PreserveFormatting := True;
xlQuery.RefreshOnFileOpen := False;
xlQuery.BackgroundQuery := True;
xlQuery.RefreshStyle := xlOverwriteCells;
xlQuery.SaveData := True;
xlQuery.AdjustColumnWidth := True;
xlQuery.RefreshPeriod := 0;
xlQuery.PreserveColumnInfo := True;
xlQuery.Refresh;
xlapp.DisplayAlerts:=false;
xlapp.Workbooks[1].SaveAs(filename);
xlapp.quit;
xlApp := Unassigned;
xlBook := Unassigned;
form1.progressbar1.Position:=100;
showmessage('我导得好辛苦啊!!') ;
form1.progressbar1.Position:=0;
end;
CoUninitialize;
end;

end.

搜索更多相关主题的帖子: ado 线程 重金 求解 
2006-09-25 16:48
快速回复:重金求解:ado多线程问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014767 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved