S
SamHunt
Unregistered / Unconfirmed
GUEST, unregistred user!
我其实想做一个线程是操作数据库的!但想同步界面!却调试不成功!
请各位帮帮忙!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls, Db, ADODB;
type
TForm1 = class(TForm)
Button1: TButton;
ProgressBar1: TProgressBar;
ADOQuery1: TADOQuery;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
type
TDBThread = class(TThread)
private
{ Private declarations }
FAdo:TAdoQuery;
procedure HookUpUI;
protected
procedure Execute;override;
public
{ Public declarations }
constructor Create;virtual;
end;
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
TDBThread.Create;
end;
{ TDBThread }
constructor TDBThread.Create;
begin
inherited Create(True);
Resume;
Execute;
end;
procedure TDBThread.Execute;
var
i:Integer;
begin
//执行下面的那一句,就报错的!
FAdo.ConnectionString :='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=IDSytem';
FAdo.SQL.Text:='Select * from Table1 ';
FAdo.Active:=false;
FAdo.Active:=true;
for i:=0 to 1000 do
begin
FAdo.Insert;
FAdo.FieldByName('Name').AsString:='aaa'+IntToStr(i);
FAdo.Post;
Synchronize(HookUpUI);
end;
end;
procedure TDBThread.HookUpUI;
begin
Form1.Label1.Caption:=FAdo.FieldByName('Name').AsString;
Form1.ProgressBar1.Position:=Form1.ProgressBar1.Position+1;
end;
end.
请各位帮帮忙!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls, Db, ADODB;
type
TForm1 = class(TForm)
Button1: TButton;
ProgressBar1: TProgressBar;
ADOQuery1: TADOQuery;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
type
TDBThread = class(TThread)
private
{ Private declarations }
FAdo:TAdoQuery;
procedure HookUpUI;
protected
procedure Execute;override;
public
{ Public declarations }
constructor Create;virtual;
end;
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
begin
TDBThread.Create;
end;
{ TDBThread }
constructor TDBThread.Create;
begin
inherited Create(True);
Resume;
Execute;
end;
procedure TDBThread.Execute;
var
i:Integer;
begin
//执行下面的那一句,就报错的!
FAdo.ConnectionString :='Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=IDSytem';
FAdo.SQL.Text:='Select * from Table1 ';
FAdo.Active:=false;
FAdo.Active:=true;
for i:=0 to 1000 do
begin
FAdo.Insert;
FAdo.FieldByName('Name').AsString:='aaa'+IntToStr(i);
FAdo.Post;
Synchronize(HookUpUI);
end;
end;
procedure TDBThread.HookUpUI;
begin
Form1.Label1.Caption:=FAdo.FieldByName('Name').AsString;
Form1.ProgressBar1.Position:=Form1.ProgressBar1.Position+1;
end;
end.