unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, ADODB, DBTables, Grids, DBGrids;type
  TForm1 = class(TForm)
    ADOConnection1: TADOConnection;
    Button2: TButton;
    ADOQuery1: TADOQuery;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button2Click(Sender: TObject);
var
  sGDDM: string;
begin
  edit1.Text := '';
  sGDDM := 'select * from FstTrade where SJYGDDM =  ' +'''' + edit1.text + '''';  ADOConnection1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\FstTrade;Extended Properties=dBase 5.0;Persist Security Info=False';  if ADOConnection1.Connected = False then ADOConnection1.Connected := True;  with ADOQuery1 do
  begin
      Active  :=   False;
      Connection   :=   ADOConnection1;
      SQL.Clear;
      SQL.Add(sGDDM);
     //  ExecSQL;
      open;
      if RecordCount > 0 then
        edit2.Text := FieldByName('SJYJYRQ').AsString;
      Active  :=  False;
      ADOConnection1.Connected := False;
  end;
end;end.

解决方案 »

  1.   

    新建一个线程类,写一个方法DoIt,实现代码中的功能,然后放到Execute方法中
    线程中用到VCL需要用线程类的同步函数Synchronize();同步 这点注意下就可以了
    代码大概想下面的样子procedure AThread.Execute;
    begin
      { Place thread code here }
      Synchronize(DoIt);
    end;
      

  2.   

    需要同主线程同步时用Synchronize同步就可以,其他和类中一样
      

  3.   


    sGDDM := 'select * from FstTrade where SJYGDDM =  ' +'''' + edit1.text + '''';这样写不会有SQL注入吗?