Subscribe

RSS Feed (xml)

Powered By

Skin Design:
Free Blogger Skins

Powered by Blogger

星期五, 11月 23, 2007

用執行序去跑ADO資料庫更新


unit Unit1;

uses unit2;

procedure TForm1.Button3Click(Sender: TObject);
begin
jjj := strtoint(Edit6.text); //jjj為記錄資料庫塞爆的全域變收

button1.enabled:=false;
TDownLoad.Create.OnTerminate := ThreadDoe;
end;

procedure TForm1.ThreadDoe(Sender: TObject);
begin
//Dec(ThreadsRunning); //減到為0又可以可以重跑 //如果TDownLoad.Create很多個同時
Button1.Enabled := True; //Thread跑完後
end;



unit Unit2;

interface

uses
Classes, ADODB, Dialogs, Forms;//這裡也使用Forms不太好

type
TDownload = class(TThread)
private
procedure Download;
{ Private declarations }
protected
procedure Execute; override;
public
constructor Create;
end;

implementation

uses Unit1;

{ TDownload }
constructor TDownload.Create;
begin
FreeOnTerminate := True;
inherited Create(False);
end;

procedure TDownload.Execute;
begin
Download;
{ Place thread code here }
end;

procedure TDownload.Download;
var
i : integer;
query1 : string;
FADOQuery : TADOQuery;
FADOConn : TADOConnection;
begin

//showmessage(Edit3.text);
FADOConn := TADOConnection.Create(nil);
FADOQuery:=TADOQuery.Create(nil);
FADOConn.ConnectionString := svr_string;
FADOConn.Connected := True;

FADOQuery.Connection := FADOConn;
try
try
for i := 0 to jjj - 1 do
begin
if not SQLExecuteOK(FADOQuery, 'insert into test (k) values (3)') then
ShowMessage('Query ERROR!!');
Application.ProcessMessages;

end;
except
showmessage('error');
end;
finally
FADOQuery.free;
FADOConn.Free;

end;
end;

end.

沒有留言: