synchronize 是同步过程的
synchronize(a);
synchronize(b);
k可以有多个
2。
线程1执行synchronize(a); 其他线程只是不能运行 a而已
3
可以,肯定是你的程序有其他问题

解决方案 »

  1.   

    我下面这个程序按说能正常运行,实际上缺有问题。报告错误为:标记没有引用存储,是怎么回事呢?另外,这里的Fadoquery非的要Create的时候指定吗?还有,由于我使用了循环来建立线程,而没有类似
    Thehe : heheThread类似的说明,所以,我要用一个按钮来中断线程,就不能用
    Thehe.Terminate方法了,这个时候我该怎么来中断线程呢?两位真有大虾风范!我穷的只剩下分了!呵呵。
    unit Unit2;interfaceuses
      Classes,adodb,stdctrls;type
      hehe = class(TThread)
        Flistbox  : Tlistbox;
        Fadoquery : Tadoquery;
      private
        { Private declarations }
      protected
        procedure Execute; override;
      public
        constructor Create(listbox : Tlistbox;q : Tadoquery);
      end;implementationconstructor hehe.Create(listbox : Tlistbox;q : Tadoquery);
    begin
      Flistbox := listbox;
      Fadoquery:= q;  FreeOnTerminate := true;  inherited Create(false);
    end;procedure hehe.Execute;
    begin
      //Fadoquery.connectionstring := 'Provider=MSDASQL.1;Persist Security Info=False;Data Source=tian';
      Fadoquery.close;
      Fadoquery.sql.clear;
      Fadoquery.sql.add('select top 10 * from Cata order by Tr');
      Fadoquery.open;  while not Fadoquery.eof do
        begin
          Flistbox.additem(Fadoquery.fieldbyname('Tr').asstring,self);
          Fadoquery.next;
        end;
    end;end.unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, DB, ADODB;type
      TForm1 = class(TForm)
        Button1: TButton;
        ListBox1: TListBox;
        ListBox2: TListBox;
        ADOQuery1: TADOQuery;
        procedure Button1Click(Sender: TObject);
      private
        procedure threadDone(Sender : Tobject);
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementationuses unit2;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    begin
      with hehe.create(Listbox1,adoquery1) do
        Onterminate := ThreadDone;
    end;procedure Tform1.threadDone(Sender : Tobject);
    begin
    end;
    end.
      

  2.   

    假如我把execute里面的东西放在 dooo 过程里,然后在execute里面synchronize(dooo),就没有问题。但是这个时候,就失去了现程的意义了。因为别的程序在这个重要环节都被挂起了。所以要是两位大虾帮到了我,实际上就是救了我!
      

  3.   

    另外,我在synchronize(dooo)里面套用synchronize(fooo),好像就会出错!怎么回事呢?也就是我最开始说的第一点!而且,假如我在Create的时候没有指定Fadoquery := q的话,运行就会出现内存错误。我想使不是除了connectionstring,还需要指定别的属性?
      

  4.   

    1、可以有多个SYNCHRONIZE()方法
    2、SYNCHRONIZE()使线程方法在主线程中执行,其它线程等待。
    3、可以。