请问线程建立时传一些参数过来用  为什么失败了   线程一开始就用Execute  好像没用过create一样   高手解答!!!type
  tmy = class(TThread)
  private
  protected
    procedure Create(我的一些参数);overload;
    procedure Execute; override;
  end;implementation
procedure tmy.Execute;
begin
//////////////////
end;procedure tmy.Create(我的一些参数);
begin
   ////////////  我写东西在这里也没有用
end;end.

解决方案 »

  1.   

    把Create放到public域,这样子创建线程的时候才能够访问到这个Create函数,否则就是调用的父类的Create
      

  2.   

    另外Create的指示字不应该是procedure,而是constructor,两者的意义在编译器看来是不一样的。procedure就是一个普通的过程,constructor的话(拿constructor Create来说),如果是一个类(基类型为TClass)类型的调用(TMy.Create),它会调用 NewInstance 创建一个对象(类的实例,基类型为TObject)实例并返回,然后再调用Create过程;如果是一个实例(var my:TMy; my.Create),直接调用Create过程,而不去调用 NewInstance 创建实例
      

  3.   

    这样还是不可以呀   我只想在建立时做一些动作  告诉我怎么办   谢谢谢type 
      tmy = class(TThread) 
      private 
      public
       constructor Create(我的一些参数);overload; 
        procedure Execute; override; 
      end; implementation 
    procedure tmy.Execute; 
    begin 
    ////////////////// 
    end; constructor tmy.Create(我的一些参数); 
    begin 
      ////////////  我写东西在这里也没有用 
    end; end. 
      

  4.   

    type
      TMyUpdateThread = class(TThread)
        private
          FUpdateEdit: TEdit;
          Counter: Integer;
        protected
          procedure Execute;override;
          procedure Update;
        public
          constructor Create(const AUpdateEdit: TEdit);
      end;
    implementationconstructor TMyUpdateThread.Create(const AUpdateEdit: TEdit);
    begin
      Inherited Create(true);
      FUpdateEdit := AUpdateEdit;
      Resume;
    end;procedure TMyUpdateThread.Update;
    begin
      FUpdateEdit.Text := IntToStr(Counter);
    end;procedure TMyUpdateThread.Execute;begin
      Counter := 0;
      while Not Terminated do begin
        Synchronize(Update);
        Sleep(1000);
        Inc(Counter);
      end;
    end;
      

  5.   

    procedure TForm6.Button1Click(Sender: TObject);
    var
      T: TMyUpdateThread;
      I: Integer;
    begin
      T := TMyUpdateThread.Create(Edit1);
      try
        I := 60 * 1000;
        while I > 0 do begin
          Application.ProcessMessages;
          Sleep(1);
          Dec(I);
          if Application.Terminated then break;
          
        end;
        T.Terminate;
        Sleep(1);
      finally
        T.Free;
      end;
    end;
      

  6.   

    楼上的  线程一开始就运作了Execute  creat中的没有做呀