Delphi的多线程查询
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, Data.Win.ADODB, Vcl.StdCtrls, Vcl.Grids, Vcl.DBGrids,ActiveX;//ActiveX一定不能少 type TForm1 = class(TForm) btn1: TButton; ds1: TDataSource; dbgrd1: TDBGrid; con1: TADOConnection; procedure btn1Click(Sender: TObject); private { Private declarations } procedure ss; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.btn1Click(Sender: TObject); begin btn1.Enabled:=False; TThread.CreateAnonymousThread(ss).Start; end; procedure TForm1.ss; var ss:TADOQuery; begin CoInitialize(nil);//函数或过程的最前 ss:=TADOQuery.Create(nil); ss.Connection:=Self.con1; ss.Close; ss.SQL.Text:='select * from oe_order_lines'; ss.Open; ds1.DataSet:=ss; btn1.Enabled:=True; CoUninitialize;//函数或过程的最后 end; end.