你已经进入死循环!!!
千万不要在主线程里调用Synchronize(...)你只能在子线程的Execute函数体中调用它。

解决方案 »

  1.   

    忘了告诉你,我是在子线程中的execute函数中调用 TRegThread.R 方法。不是在主线程里面。
      

  2.   

    procedure TRegThread.R(temps: string);
    begin
      
      Ftemps      := temps;
      showmessage('进入R');
      
      Synchronize(TRThread.doR);
    end;procedure TRThread.doR;
    begin
        showmessage('进入doR境界');
    end;
      

  3.   

    procedure TRegThread.R(temps: string);
    begin
      
      Ftemps      := temps;
      showmessage('进入R');
      //应该是这样,创建trthread实例t,然后调用t.dor
      Synchronize(t.doR);
    end;procedure TRThread.doR;
    begin
        showmessage('进入doR境界');
    end;
      

  4.   

    对,wisure(Delphi-我决不放手) 说得对!
      

  5.   

    wisure老哥,你给的方法连编译都不能过关。呵呵。
      

  6.   

    什么意思呢?
    我已经在主线程中
         with TRThread.Create() do
           OnTerminate := ThreadDone;
    了。那么这个时候还需要怎么创建实例呢?我看demo中的例子是不需要额外创建的啊。
      

  7.   

    var t:TRThread;t := TRThread.Create;
         with t do
           OnTerminate := ThreadDone;......
    procedure TRegThread.R(temps: string);
    begin
      
      Ftemps      := temps;
      showmessage('进入R');
      //应该是这样,创建trthread实例t,然后调用t.dor
      Synchronize(t.doR);
    end;procedure TRThread.doR;
    begin
        showmessage('进入doR境界');
    end;
      

  8.   

    大民兄,我的线程函数在一个独立的unit里,你的方法不是让我在这个unit里面uses 主程序的unit吧!否则根本编译不了。假如真的要uses的话,我想绝对是不需要的。
      

  9.   

    你把
    procedure TRThread.doR;
    begin
        showmessage('进入doR境界');
    end;改为:
    procedure TRegThread.doR;
    begin
        showmessage('进入doR境界');
    end;即OK!
      

  10.   

    两个线程类不一样,就需要分别创建两个线程的实例,如果用的是一个类,你说我的方法编译同不过可能是你没有创建trthread的实例,只是使用TRegThread的实例,所以不能通过编译,我这里没有delphi,没有办法确认,抱歉
      

  11.   

    给你一个完整的例子,我调试通过:unit Unit2;interfaceuses
      Classes,Dialogs;type
      TRegThread = class(TThread)
      private
        { Private declarations }
        FTempS: String;
        procedure doR;
        procedure R(temps: string);
      protected
        procedure Execute; override;
      end;implementation{ Important: Methods and properties of objects in VCL or CLX can only be used
      in a method called using Synchronize, for example,      Synchronize(UpdateCaption);  and UpdateCaption could look like,    procedure TRegThread.UpdateCaption;
        begin
          Form1.Caption := 'Updated in a thread';
        end; }{ TRegThread }
    procedure TRegThread.R(temps: string);
    begin
      Ftemps      := temps;
      showmessage('进入R');  Synchronize(doR);end;
    procedure TRegThread.doR;
    begin
        showmessage('进入doR境界');
    end;procedure TRegThread.Execute;
    begin
      { Place thread code here }
      R('here!');
    end;end.
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementationuses Unit2;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);begin
      TRegThread.Create(FALSE);
      //     OnTerminate := ThreadDone;
    end;end.
      

  12.   

    问题稀里糊涂的解决了!我没有使用syn方法就好了!