看到个例子,建立一个ADOQUERY查询的线程
那主窗体怎么用这个线程,怎么调用,怎么销毁???
刚开始学,按例子做
先声明
var t:unit1;      //UNIT1是主窗体
begin
t:=unit1.Create(adoquery1,'select * from TABLE');第一步var就提示错误了
E2029 '.' expected but ';' found主窗体只有一个ADOQUERY,一个按钮,一个DBGRID,一个DS请问要怎么调用???以下是线程的代码
unit Unit2;interfaceuses
  Classes,ADODB,SysUtils,ActiveX;type
  Unit1 = class(TThread)
  constructor Create(ado:Tadoquery;s:string);//+
  destructor Destroy;override;               //+
  private
    a:Tadoquery;
    ss:string;
    { Private declarations }
  protected
    procedure Execute; override;
  end;implementationuses Unit1;{ Important: Methods and properties of objects in visual components can only be
  used in a method called using Synchronize, for example,      Synchronize(UpdateCaption);  and UpdateCaption could look like,    procedure Unit1.UpdateCaption;
    begin
      Form1.Caption := 'Updated in a thread';
    end; }{ Unit1 }constructor Unit1.Create(ado:Tadoquery;s:string);     //+
begin
  inherited create(true);
  FreeOnTerminate:=true;
  a:=ado;
  ss:=s;
  Resume;
end;procedure Unit1.Execute;
begin
  { Place thread code here }
  CoInitialize(nil);//必须的
  sleep(5000);
  a.SQL.Add(ss);
  try
    a.Open;
  except
    raise
  end;
end;destructor Unit1.Destroy;         //+
begin
  a:=nil;
  inherited Destroy;
end;
end.

解决方案 »

  1.   

    看你的代码没看到有应该报那个错的地方。你看一下你的窗体的单元,最后一个end应该是.号的,你是不是变成;了
      

  2.   

    E2029 '.' expected but ';' found
    这句是说应该用.号而你用了;号.
      

  3.   

    Unit1 = class(TThread)
    这个怎么也用unit1呢,unit1不是主窗体吗,不能重复
      

  4.   

    刚刚新加了个UNIT3作为主窗体,也是一样啊 ~~~~线程的那个代码没报错
    是主窗体里声明线程哪里报错
    var t:unit1;这里就提示错了,而且是提示 E2029 '.' expected but ';' found  这个所以很奇怪
      

  5.   

    constructor Unit1.Create(ado:Tadoquery;s:string);     //+
    begin
      inherited create(true);CoInitialize(nil);//必须的 ,注意释放哦,好习惯。  FreeOnTerminate:=true;
      a:=ado;
      ss:=s;
      Resume;
    end;procedure Unit1.Execute;
    begin
      { Place thread code here }
      //CoInitialize(nil);//必须的
      sleep(5000);
      a.SQL.Add(ss);
      try
        a.Open;
      except
        raise  //不能这样,这里的异常不能举起,可以考虑WriteLog
      end;
    end;
      

  6.   

    谢谢 zhangxuyu1118  
    我是想问主窗体怎么运行这个线程
    声明的时候就报错了
      

  7.   

    我看了你的帖子,感觉你啥都不懂。
    “var t:unit1;      //UNIT1是主窗体” 
    还是好好看书吧。
      

  8.   

    回dd_zhouqian 
    unit1不是主窗体了
    就是不懂才问啊!!