请大家帮忙了!

解决方案 »

  1.   

    unit MyThreadPro;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        UsedThread: TButton;
        NoUsedThread: TButton;
        procedure UsedThreadClick(Sender: TObject);
        procedure NoUsedThreadClick(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}function MyThreadFunc(P:pointer):Longint;stdcall;
    var
       i:integer;
       DC:HDC;
       S:string;
    begin
         DC:=GetDC(Form1.Handle);
         for i:=0 to 100000 do begin
             S:=Inttostr(i);
             Textout(DC,10,10,Pchar(S),length(S));
         end;
         ReleaseDC(Form1.Handle,DC);
    end;procedure TForm1.UsedThreadClick(Sender: TObject);
    var
       hThread:Thandle;//定义一个句柄
       ThreadID:DWord;
    begin
    //创建线程,同时线程函数被调用
    hthread:=CreateThread(nil,0,@MyThreadfunc,nil,0,ThreadID);
         if hThread=0 then
    messagebox(Handle,'Didn’t Create a Thread',nil,MB_OK);
    end;procedure TForm1.NoUsedThreadClick(Sender: TObject);
    begin
         MyThreadfunc(nil); 
    //没有创建线程时,直接调用线程函数
    end;end.
      

  2.   

    unit unit1
    interface
    uses classes;
    type
    TMyThread1=class(TThread)
    private
    {Private declarations}
    protected
    procedure Execute;overide;
    end;
    implementation
    .......procedure TMyThread1.Execute;
    begin
    ...{place thread code here}
    end;
    end.
    在execute方法中编写该进程要执行的任务。
      

  3.   

    Delphi 有自带的例子!!!
      

  4.   

    Delphi目录下Demos\Threads下的工程文件可能对你有用
      

  5.   

    CreateThread (Form1.Handle, @functionName, functionParm,0
                 );看Win Api32 SDK 帮助