L
lwbcool
Unregistered / Unconfirmed
GUEST, unregistred user!
以下为源码,不知道怎么修改,规求!
================
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus, ComCtrls, DB, ADODB,activex;
const
START = 9;
CMD = 0;
ERR = 1;
FRONT = 2;
MEG = 3;
REP = 4;
FRTREP =5 ;
type
TThreadQuery = class(TThread) { 声明线程类 }
private
QueryType: String;
{ 线程中的查询组件 }
Dqquery,Dqquery1:TAdoquery;
protected
procedure Execute;
override;{ 执行线程的方法 }
public
constructor Create(suspended: Boolean);
{ 线程构造器 }
destructor Destroy;override;
end;
TForm1 = class(TForm)
GroupBox1: TGroupBox;
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
RichEdit1: TRichEdit;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
N3: TMenuItem;
procedure N2Click(Sender: TObject);
procedure DisplayMsg(msgtype:integer;Data:Ansistring;flag:Ansistring);
procedure N3Click(Sender: TObject);
procedure N4Click(Sender: TObject);
procedure win_api;
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
ThreadQuery: TThreadQuery;
{ 线程查询对象1 }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.win_api;
//win32错误 87 参数不正确
var st:TStartUpInfo;pp:TProcessInformation;ppp:Thandle;tt:Cardinal;
begin
try
FillChar(st,sizeof(st),#0);
with stdo
begin
cb:=sizeof(st);
dwFlags:=StartF_UsesTDHandles or STARTF_USESHOWWINDOW;
lptitle:=nil;
wShowWindow:=SW_HIDE;
end;
CreateProcess('',nil,nil,nil,true,DETACHED_PROCESS,nil,nil,st,pp);
ppp:=OpenProcess(PROCESS_ALL_ACCESS, FALSE,pp.dwProcessId );
GetExitCodeProcess(ppp,tt);
Exitprocess(tt);
except
end;
end;
procedure TForm1.DisplayMsg(msgtype:integer;Data:Ansistring;flag:Ansistring);
var
FileName:String;
f:system.textfile;
begin
FileName:=formatdatetime('yyyymmdd',now)+'.txt';
if not DirectoryExists(ExtractFilePath(Application.ExeName)+'Log') then
SysUtils.CreateDir(ExtractFilePath(Application.ExeName)+'Log');
AssignFile(f,ExtractFilePath(Application.ExeName)+'Log/'+ FileName);
if not FileExists(ExtractFilePath(Application.ExeName)+'Log/'+ FileName) then
Rewrite(f);
if FileExists(ExtractFilePath(Application.ExeName)+'Log/'+ FileName) then
Append(f);
with RichEdit1do
begin
Try
begin
if Lines.Count>50 then
Lines.Clear;
case msgtype of
CMD:begin
SelAttributes.Color := clGreen;
Lines.Add(FormatDateTime('hh:nn:ss',now)+'|开始|'+Data);
Repaint;
if flag = '1' then
Writeln(f,FormatDateTime('yyyymmdd|hh:nn:ss',now)+'|开始|'+Data);
end;
ERR:begin
SelAttributes.Color := clRed;
Lines.Add(FormatDateTime('hh:nn:ss',now)+'|失败|'+Data);
Repaint;
if flag = '1' then
Writeln(f,FormatDateTime('yyyymmdd|hh:nn:ss',now)+'|失败|'+Data);
end;
FRONT:begin
SelAttributes.Color := clBlue;
Lines.Add(FormatDateTime('hh:nn:ss',now)+'|执行|'+Data);
Repaint;
if flag = '1' then
Writeln(f,FormatDateTime('yyyymmdd|hh:nn:ss',now)+'|执行|'+Data);
end;
MEG:begin
SelAttributes.Color := clBlue;
Lines.Add(FormatDateTime('hh:nn:ss',now)+'|信息|'+Data);
if flag = '1' then
Writeln(f,FormatDateTime('yyyymmdd|hh:nn:ss',now)+'|信息|'+Data);
Repaint;
end;
REP:begin
SelAttributes.Color := clBlack;
Lines.Add(FormatDateTime('hh:nn:ss',now)+'|完成|'+Data);
Repaint;
if flag = '1' then
Writeln(f,FormatDateTime('yyyymmdd|hh:nn:ss',now)+'|完成|'+Data);
end;
FRTREP:begin
SelAttributes.Color := clBlue;
Lines.Add(FormatDateTime('hh:nn:ss',now)+'|退出|'+Data);
Repaint;
if flag = '1' then
Writeln(f,FormatDateTime('yyyymmdd|hh:nn:ss',now)+'|RECVE|'+Data);
end;
START:begin
SelAttributes.Color := clTeal;
Lines.Add(FormatDateTime('hh:nn:ss',now)+'|初始化|'+data);
Repaint;
if flag = '1' then
Writeln(f,FormatDateTime('yyyymmdd|hh:nn:ss',now)+'|初始化|'+Data);
end;
end;
{case}
end;
Except
SelAttributes.Color := clRed;
Lines.Add(FormatDateTime('hh:nn:ss',now)+'|ERR|[非法字符串或超长]');
end;
{Try}
end;
{with}
CloseFile(f);
end;
{ TThreadQuery类的实现 }
destructor TThreadQuery.Destroy;
begin
Dqquery.free;
Dqquery1.Free;
Dqquery.Connection.Free;
Dqquery.Connection.Free;
inherited destroy;
end ;
procedure TThreadQuery.Execute;{ 执行线程的方法 }
var
zoneno,spotno,upspotno:String;
begin
coInitialize(nil);
try
Dqquery:=TAdoquery.Create(nil);
Dqquery.Connection:=Form1.ADOConnection1;
with Dqquerydo
begin
if not active then
begin
Dqquery.close;
Dqquery.sql.clear;
Dqquery.sql.add('select zoneno ,spotno,upspotno from updatespot where upspotno is not null ');
try
Dqquery.open;
except
Form1.displaymsg(Err,'数据库出错','1');
Form1.displaymsg(FRTREP,'操作','1');
exit;
end;
end;
first;
while not eofdo
begin
zoneno:=Dqquery.FieldByName('zoneno').asString;
spotno:=Dqquery.FieldByName('spotno').asString;
upspotno:=Dqquery.FieldByName('upspotno').asString;
if Dqquery.FieldByName('upspotno').IsNull then
begin
Form1.displaymsg(REP,'检查','1');
end
else
begin
Dqquery1:=TAdoquery.Create(nil);
Dqquery1.Connection:=Form1.ADOConnection1;
with Dqquery1do
begin
close;
sql.clear;
sql.Add('update pregcard');
sql.add(' set yxspot= '''+upspotno+'''');
sql.add(' where yxspot= '''+spotno+'''');
sql.add(' and zoneno= '''+zoneno+'''');
try
try
Form1.DisplayMsg(CMD,sql.Text,'1');
execsql;
except
Form1.displaymsg(Err,'更新失败','1');
Form1.displaymsg(FRTREP,'操作','1');Close;
exit;
end;
Form1.displaymsg(REP,'更新个人支行号','1');
finally
//Dqquery1.Close;
end;
{try}
end;
end;
next;
end;
//Dqquery.Close;
end;
Dqquery.Free;
Dqquery1.Free;
Form1.displaymsg(Meg,'执行完成!','1');
except
ShowMessage('线程异常!');
{ 线程异常 }
end;
CoUninitialize;
end;
{ 线程查询类的构造器 }
constructor TThreadQuery.Create(suspended: Boolean);
begin
FreeOnTerminate := True;
inherited Create(suspended);
end;
procedure TForm1.N2Click(Sender: TObject);
begin
try
displaymsg(start,'创建线程...','1');
ThreadQuery:= TThreadQuery.Create(True);
ThreadQuery.Resume;
displaymsg(start,'创建线程成功!','1');
except
displaymsg(Err,'创建线程失败!','1');
end;
//try
displaymsg(start,'创建线程完成!','1');
end;
procedure TForm1.N3Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.N4Click(Sender: TObject);
begin
try
displaymsg(Meg,'结束线程...','1');
ThreadQuery.Terminate;
ThreadQuery.Free;
displaymsg(Meg,'结束线程成功!','1');
except
displaymsg(Err,'结束线程失败!','1');
end;
end;
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
//win_api;
application.Terminate;
end;
end.
================
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus, ComCtrls, DB, ADODB,activex;
const
START = 9;
CMD = 0;
ERR = 1;
FRONT = 2;
MEG = 3;
REP = 4;
FRTREP =5 ;
type
TThreadQuery = class(TThread) { 声明线程类 }
private
QueryType: String;
{ 线程中的查询组件 }
Dqquery,Dqquery1:TAdoquery;
protected
procedure Execute;
override;{ 执行线程的方法 }
public
constructor Create(suspended: Boolean);
{ 线程构造器 }
destructor Destroy;override;
end;
TForm1 = class(TForm)
GroupBox1: TGroupBox;
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
RichEdit1: TRichEdit;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
N3: TMenuItem;
procedure N2Click(Sender: TObject);
procedure DisplayMsg(msgtype:integer;Data:Ansistring;flag:Ansistring);
procedure N3Click(Sender: TObject);
procedure N4Click(Sender: TObject);
procedure win_api;
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
ThreadQuery: TThreadQuery;
{ 线程查询对象1 }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.win_api;
//win32错误 87 参数不正确
var st:TStartUpInfo;pp:TProcessInformation;ppp:Thandle;tt:Cardinal;
begin
try
FillChar(st,sizeof(st),#0);
with stdo
begin
cb:=sizeof(st);
dwFlags:=StartF_UsesTDHandles or STARTF_USESHOWWINDOW;
lptitle:=nil;
wShowWindow:=SW_HIDE;
end;
CreateProcess('',nil,nil,nil,true,DETACHED_PROCESS,nil,nil,st,pp);
ppp:=OpenProcess(PROCESS_ALL_ACCESS, FALSE,pp.dwProcessId );
GetExitCodeProcess(ppp,tt);
Exitprocess(tt);
except
end;
end;
procedure TForm1.DisplayMsg(msgtype:integer;Data:Ansistring;flag:Ansistring);
var
FileName:String;
f:system.textfile;
begin
FileName:=formatdatetime('yyyymmdd',now)+'.txt';
if not DirectoryExists(ExtractFilePath(Application.ExeName)+'Log') then
SysUtils.CreateDir(ExtractFilePath(Application.ExeName)+'Log');
AssignFile(f,ExtractFilePath(Application.ExeName)+'Log/'+ FileName);
if not FileExists(ExtractFilePath(Application.ExeName)+'Log/'+ FileName) then
Rewrite(f);
if FileExists(ExtractFilePath(Application.ExeName)+'Log/'+ FileName) then
Append(f);
with RichEdit1do
begin
Try
begin
if Lines.Count>50 then
Lines.Clear;
case msgtype of
CMD:begin
SelAttributes.Color := clGreen;
Lines.Add(FormatDateTime('hh:nn:ss',now)+'|开始|'+Data);
Repaint;
if flag = '1' then
Writeln(f,FormatDateTime('yyyymmdd|hh:nn:ss',now)+'|开始|'+Data);
end;
ERR:begin
SelAttributes.Color := clRed;
Lines.Add(FormatDateTime('hh:nn:ss',now)+'|失败|'+Data);
Repaint;
if flag = '1' then
Writeln(f,FormatDateTime('yyyymmdd|hh:nn:ss',now)+'|失败|'+Data);
end;
FRONT:begin
SelAttributes.Color := clBlue;
Lines.Add(FormatDateTime('hh:nn:ss',now)+'|执行|'+Data);
Repaint;
if flag = '1' then
Writeln(f,FormatDateTime('yyyymmdd|hh:nn:ss',now)+'|执行|'+Data);
end;
MEG:begin
SelAttributes.Color := clBlue;
Lines.Add(FormatDateTime('hh:nn:ss',now)+'|信息|'+Data);
if flag = '1' then
Writeln(f,FormatDateTime('yyyymmdd|hh:nn:ss',now)+'|信息|'+Data);
Repaint;
end;
REP:begin
SelAttributes.Color := clBlack;
Lines.Add(FormatDateTime('hh:nn:ss',now)+'|完成|'+Data);
Repaint;
if flag = '1' then
Writeln(f,FormatDateTime('yyyymmdd|hh:nn:ss',now)+'|完成|'+Data);
end;
FRTREP:begin
SelAttributes.Color := clBlue;
Lines.Add(FormatDateTime('hh:nn:ss',now)+'|退出|'+Data);
Repaint;
if flag = '1' then
Writeln(f,FormatDateTime('yyyymmdd|hh:nn:ss',now)+'|RECVE|'+Data);
end;
START:begin
SelAttributes.Color := clTeal;
Lines.Add(FormatDateTime('hh:nn:ss',now)+'|初始化|'+data);
Repaint;
if flag = '1' then
Writeln(f,FormatDateTime('yyyymmdd|hh:nn:ss',now)+'|初始化|'+Data);
end;
end;
{case}
end;
Except
SelAttributes.Color := clRed;
Lines.Add(FormatDateTime('hh:nn:ss',now)+'|ERR|[非法字符串或超长]');
end;
{Try}
end;
{with}
CloseFile(f);
end;
{ TThreadQuery类的实现 }
destructor TThreadQuery.Destroy;
begin
Dqquery.free;
Dqquery1.Free;
Dqquery.Connection.Free;
Dqquery.Connection.Free;
inherited destroy;
end ;
procedure TThreadQuery.Execute;{ 执行线程的方法 }
var
zoneno,spotno,upspotno:String;
begin
coInitialize(nil);
try
Dqquery:=TAdoquery.Create(nil);
Dqquery.Connection:=Form1.ADOConnection1;
with Dqquerydo
begin
if not active then
begin
Dqquery.close;
Dqquery.sql.clear;
Dqquery.sql.add('select zoneno ,spotno,upspotno from updatespot where upspotno is not null ');
try
Dqquery.open;
except
Form1.displaymsg(Err,'数据库出错','1');
Form1.displaymsg(FRTREP,'操作','1');
exit;
end;
end;
first;
while not eofdo
begin
zoneno:=Dqquery.FieldByName('zoneno').asString;
spotno:=Dqquery.FieldByName('spotno').asString;
upspotno:=Dqquery.FieldByName('upspotno').asString;
if Dqquery.FieldByName('upspotno').IsNull then
begin
Form1.displaymsg(REP,'检查','1');
end
else
begin
Dqquery1:=TAdoquery.Create(nil);
Dqquery1.Connection:=Form1.ADOConnection1;
with Dqquery1do
begin
close;
sql.clear;
sql.Add('update pregcard');
sql.add(' set yxspot= '''+upspotno+'''');
sql.add(' where yxspot= '''+spotno+'''');
sql.add(' and zoneno= '''+zoneno+'''');
try
try
Form1.DisplayMsg(CMD,sql.Text,'1');
execsql;
except
Form1.displaymsg(Err,'更新失败','1');
Form1.displaymsg(FRTREP,'操作','1');Close;
exit;
end;
Form1.displaymsg(REP,'更新个人支行号','1');
finally
//Dqquery1.Close;
end;
{try}
end;
end;
next;
end;
//Dqquery.Close;
end;
Dqquery.Free;
Dqquery1.Free;
Form1.displaymsg(Meg,'执行完成!','1');
except
ShowMessage('线程异常!');
{ 线程异常 }
end;
CoUninitialize;
end;
{ 线程查询类的构造器 }
constructor TThreadQuery.Create(suspended: Boolean);
begin
FreeOnTerminate := True;
inherited Create(suspended);
end;
procedure TForm1.N2Click(Sender: TObject);
begin
try
displaymsg(start,'创建线程...','1');
ThreadQuery:= TThreadQuery.Create(True);
ThreadQuery.Resume;
displaymsg(start,'创建线程成功!','1');
except
displaymsg(Err,'创建线程失败!','1');
end;
//try
displaymsg(start,'创建线程完成!','1');
end;
procedure TForm1.N3Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.N4Click(Sender: TObject);
begin
try
displaymsg(Meg,'结束线程...','1');
ThreadQuery.Terminate;
ThreadQuery.Free;
displaymsg(Meg,'结束线程成功!','1');
except
displaymsg(Err,'结束线程失败!','1');
end;
end;
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
//win_api;
application.Terminate;
end;
end.