F
fbyang
Unregistered / Unconfirmed
GUEST, unregistred user!
调用方法:
(transThread.Create(adcConfigConnection.ConnectionString,1) ).OnTerminate :=ThreadDone ;
ThreadDone函数只是做了线程数的更新
线程代码:
unit Uit_TransThread;
interface
uses
windows,SysUtils,Classes, Dialogs,ADODB,db, ActiveX;
type
transThread = class(TThread)
private
sMetaViewSQL,sTargetTable:String ;
sConfigConnStr,sTargetConnStr,sMetaConnStr:String ;
iTransSubjectID:integer ;
adoTargetConnection:TAdoConnection ;
adoMetaConnection,adoConfigConnection:TAdoConnection ;
cdsTargetField,adoConfig_Log,adoMetaQuery,adoTemp,adoTargetQuery:TAdoQuery ;
//thread
Destructor Destroy;
procedure TransData;
{ Private declarations }
protected
procedure Execute;
override;
public
constructor Create(ConfigConnStr:String;TransSubjectID:Integer);
end;
implementation
{ transThread }
procedure transThread.Execute;
begin
TransData ;
end;
constructor transThread.Create(ConfigConnStr:String;TransSubjectID:Integer);
begin
inherited Create(False);
CoInitialize( nil );//使用com对象必须要初始化
FreeOnTerminate := True;
iTransSubjectID := TransSubjectID ;
sConfigConnStr := ConfigConnStr ;
adoTargetConnection:=Tadoconnection.Create(nil);//动态生成的连接
adoMetaconnection := tAdoConnection.Create(nil);
adoConfigConnection := TAdoConnection.Create(nil);
adoconfigconnection.LoginPrompt :=false;
adoConfigconnection.ConnectionString := sConfigConnStr ;
adoConfigconnection.KeepConnection :=false;
adoTargetConnection.LoginPrompt :=false;
adoTargetConnection.ConnectionString := sTargetConnStr ;
adoTargetConnection.KeepConnection :=false;
adoMetaconnection.LoginPrompt :=false;
adoMetaconnection.ConnectionString := sMetaConnStr ;
adoMetaconnection.KeepConnection :=false;
adoConfig_Log := TAdoQuery.Create(nil);
adoConfig_Log.Connection := adoConfigConnection ;
adoMetaQuery := TAdoQuery.Create(nil);
adoMetaQuery.Connection := adoMetaConnection ;
adoTargetQuery := TAdoQuery.Create(nil) ;
adoTargetQuery.connection := adoTargetConnection ;
cdsTargetField := TAdoQuery.Create(nil) ;
cdsTargetField.Connection := adoConfigConnection ;
cdsTargetField.SQL.Text := 'select * from Field_comp where DS_INT_ID = ' +IntToStr(iTransSubjectID) ;//thread
cdsTargetField.Open ;//thread
adoTemp := TAdoQuery.Create(nil);
adoTemp.Connection := adoConfigConnection ;
adoTemp.SQL.text := 'select * from data_subject where DS_INT_ID = ' +IntToStr(iTransSubjectID) ;//thread
adoTemp.Open ;
sMetaViewSQL := adoTemp.fieldByName('DS_CH_MDATA').AsString ;
sTargetTable := adoTemp.fieldByName('DS_CH_TAGDATA').AsString ;
sMetaConnStr := adoTemp.fieldByName('DS_CH_METASTR').AsString ;
sTargetConnStr := adoTemp.fieldByName('DS_CH_TAGSTR').AsString ;
adotemp.Close ;
end;
destructor transThread.Destroy;
begin
cdsTargetField.Active := false ;
adoConfig_Log.Active := false ;
adoMetaQuery.Active := false ;
adoTemp.Active := false ;
adoTargetQuery.Active := false ;
//cdsTargetField.Free ;
//adoConfig_Log.Free ;
//adoMetaQuery.Free ;
//adoTemp.Free ;
//adoTargetQuery.Free ;
//cdsTargetField := nil ;
//adoConfig_Log := nil ;
//adoMetaQuery := nil ;
//adoTemp := nil ;
//adoTargetQuery := nil ;
//cdsTargetField.Destroy ;
//adoConfig_Log.Destroy ;
//adoMetaQuery.Destroy ;
//adoTemp.Destroy ;
//adoTargetQuery.Destroy ;
FreeAndNil(cdsTargetField) ;
FreeAndNil(adoConfig_Log) ;
FreeAndNil(adoMetaQuery) ;
FreeAndNil(adoTemp) ;
FreeAndNil(adoTargetQuery) ;
adoMetaConnection.Connected := false ;
adoConfigConnection.Connected := false ;
adoTargetConnection.Connected := false ;
//adoMetaConnection.Free ;
//adoConfigConnection.Free ;
//adoTargetConnection.Free ;
//adoMetaConnection.Destroy ;
//adoConfigConnection.Destroy ;
//adoTargetConnection.Destroy ;
FreeAndNil(adoMetaConnection) ;
FreeAndNil(adoConfigConnection) ;
FreeAndNil(adoTargetConnection) ;
//adoMetaConnection := nil ;
//adoConfigConnection := nil ;
//adoTargetConnection:= nil ;
CoUnInitialize;//必须使用
inherited destroy;
end;
procedure transThread.TransData;
begin
//本来有代码,这里暂时删除,因为我把这里代码注释的情况下,内存还是不断上涨
end ;
end.
(transThread.Create(adcConfigConnection.ConnectionString,1) ).OnTerminate :=ThreadDone ;
ThreadDone函数只是做了线程数的更新
线程代码:
unit Uit_TransThread;
interface
uses
windows,SysUtils,Classes, Dialogs,ADODB,db, ActiveX;
type
transThread = class(TThread)
private
sMetaViewSQL,sTargetTable:String ;
sConfigConnStr,sTargetConnStr,sMetaConnStr:String ;
iTransSubjectID:integer ;
adoTargetConnection:TAdoConnection ;
adoMetaConnection,adoConfigConnection:TAdoConnection ;
cdsTargetField,adoConfig_Log,adoMetaQuery,adoTemp,adoTargetQuery:TAdoQuery ;
//thread
Destructor Destroy;
procedure TransData;
{ Private declarations }
protected
procedure Execute;
override;
public
constructor Create(ConfigConnStr:String;TransSubjectID:Integer);
end;
implementation
{ transThread }
procedure transThread.Execute;
begin
TransData ;
end;
constructor transThread.Create(ConfigConnStr:String;TransSubjectID:Integer);
begin
inherited Create(False);
CoInitialize( nil );//使用com对象必须要初始化
FreeOnTerminate := True;
iTransSubjectID := TransSubjectID ;
sConfigConnStr := ConfigConnStr ;
adoTargetConnection:=Tadoconnection.Create(nil);//动态生成的连接
adoMetaconnection := tAdoConnection.Create(nil);
adoConfigConnection := TAdoConnection.Create(nil);
adoconfigconnection.LoginPrompt :=false;
adoConfigconnection.ConnectionString := sConfigConnStr ;
adoConfigconnection.KeepConnection :=false;
adoTargetConnection.LoginPrompt :=false;
adoTargetConnection.ConnectionString := sTargetConnStr ;
adoTargetConnection.KeepConnection :=false;
adoMetaconnection.LoginPrompt :=false;
adoMetaconnection.ConnectionString := sMetaConnStr ;
adoMetaconnection.KeepConnection :=false;
adoConfig_Log := TAdoQuery.Create(nil);
adoConfig_Log.Connection := adoConfigConnection ;
adoMetaQuery := TAdoQuery.Create(nil);
adoMetaQuery.Connection := adoMetaConnection ;
adoTargetQuery := TAdoQuery.Create(nil) ;
adoTargetQuery.connection := adoTargetConnection ;
cdsTargetField := TAdoQuery.Create(nil) ;
cdsTargetField.Connection := adoConfigConnection ;
cdsTargetField.SQL.Text := 'select * from Field_comp where DS_INT_ID = ' +IntToStr(iTransSubjectID) ;//thread
cdsTargetField.Open ;//thread
adoTemp := TAdoQuery.Create(nil);
adoTemp.Connection := adoConfigConnection ;
adoTemp.SQL.text := 'select * from data_subject where DS_INT_ID = ' +IntToStr(iTransSubjectID) ;//thread
adoTemp.Open ;
sMetaViewSQL := adoTemp.fieldByName('DS_CH_MDATA').AsString ;
sTargetTable := adoTemp.fieldByName('DS_CH_TAGDATA').AsString ;
sMetaConnStr := adoTemp.fieldByName('DS_CH_METASTR').AsString ;
sTargetConnStr := adoTemp.fieldByName('DS_CH_TAGSTR').AsString ;
adotemp.Close ;
end;
destructor transThread.Destroy;
begin
cdsTargetField.Active := false ;
adoConfig_Log.Active := false ;
adoMetaQuery.Active := false ;
adoTemp.Active := false ;
adoTargetQuery.Active := false ;
//cdsTargetField.Free ;
//adoConfig_Log.Free ;
//adoMetaQuery.Free ;
//adoTemp.Free ;
//adoTargetQuery.Free ;
//cdsTargetField := nil ;
//adoConfig_Log := nil ;
//adoMetaQuery := nil ;
//adoTemp := nil ;
//adoTargetQuery := nil ;
//cdsTargetField.Destroy ;
//adoConfig_Log.Destroy ;
//adoMetaQuery.Destroy ;
//adoTemp.Destroy ;
//adoTargetQuery.Destroy ;
FreeAndNil(cdsTargetField) ;
FreeAndNil(adoConfig_Log) ;
FreeAndNil(adoMetaQuery) ;
FreeAndNil(adoTemp) ;
FreeAndNil(adoTargetQuery) ;
adoMetaConnection.Connected := false ;
adoConfigConnection.Connected := false ;
adoTargetConnection.Connected := false ;
//adoMetaConnection.Free ;
//adoConfigConnection.Free ;
//adoTargetConnection.Free ;
//adoMetaConnection.Destroy ;
//adoConfigConnection.Destroy ;
//adoTargetConnection.Destroy ;
FreeAndNil(adoMetaConnection) ;
FreeAndNil(adoConfigConnection) ;
FreeAndNil(adoTargetConnection) ;
//adoMetaConnection := nil ;
//adoConfigConnection := nil ;
//adoTargetConnection:= nil ;
CoUnInitialize;//必须使用
inherited destroy;
end;
procedure transThread.TransData;
begin
//本来有代码,这里暂时删除,因为我把这里代码注释的情况下,内存还是不断上涨
end ;
end.