线程:
//文件1
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
mythread:dbthread;
begin
mythread:=dbthread.Create(False);
//your sql code put here
//after query
mythread.suspend;
mythread.Free;
label1.caption:='finish';
end;
end.
//文件2
unit Unit2;
interface
uses
Classes;
type
dbthread = class(TThread)
private
{ Private declarations }
procedure UpdateCaption;
protected
procedure Execute;
override;
end;
implementation
uses
unit1;
{ Important: Methods and properties of objects in VCL can only be used in a
method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure dbthread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end;
}
{ dbthread }
procedure dbthread.updatecaption;
var
I:integer;
begin
for I:=0 to 1000000do
form1.label1.Caption:='please wait for query finished '+inttostr(I);
end;
procedure dbthread.Execute;
begin
{ Place thread code here }
synchronize(updatecaption);
end;
end.