//简单一点uses
  Classes, SysUtils, Forms, mystruct, Windows, ComCtrls, DB, ADODB, Messages, ActiveX;Function Tmythread.Query(PNode : TTreeNode) : Boolean;
var
   adoq : TADOQuery;
begin
  try
     CoInitialize(nil);
     try
        with adoq do
        begin
           ConnectionString := main.constr;  //这里就出错了,在别的单元里用好的。错误见下面
           close;
           sql.Clear;
           //其他代码
         end;//with
     finally
       ADOq.free;
     end;
  finally
     CoUninitialize;
     result := True;
  end;
end;

解决方案 »

  1.   

    你在访问main.constr发生冲突,可以使用临界区在访main.constr进行保护互斥也可以!信号就不必使用了!
      

  2.   

    我现在把connstr用参数传进来了,还是不行呀。怎么回事?type
      Tmythread = class(TThread)
      private
        PFhIp : PStrIp;
        constr : String;
        rec : Boolean;
      protected
        procedure Execute; override;
        Function Query( PNode: TTreeNode) : Boolean;
      Public
        constructor Create(TFhIp : TstrIp; Connstr : String; recording : Boolean);
        Destructor Destroy; Override;
      end;
    procedure Tmythread.Execute;
    begin
      { Place thread code here }
      FreeOnTerminate := True; //线程做完后终止
      if not terminated then
      Stordata;
    end;
    Function Tmythread.Query(PNode : TTreeNode) : Boolean;
    var
       adoq : TADOQuery;
    begin
      try
         CoInitialize(nil);
         try
            with adoq do
            begin
               ConnectionString := constr;
               Active := False;
               sql.Clear;
               //其他操作。
            end;//with
         finally
           ADOq.free;
         end;
      finally
         CoUninitialize;
         result := True;
      end;
    end;
      

  3.   


    ConnectionString := constr;  //再下去就出错了