关于CreateThread()中的参数lpParameter如何使用?lpParameter是指线程的执行函数的参数地址,那我在执行函数中如何得到这个参数!最好有个简单例子!谢谢!

解决方案 »

  1.   

    type
      TPingIPThread = class(TThread)
      private
        { Private declarations }
        FchannelStr:string;
        FcolInt:integer;
      protected
        procedure Execute; override;
      public
        constructor Create(par_channelStr:string;Par_colInt:integer);
      end;
    implementation
    uses poskjg;{ TPingIPThread }procedure TPingIPThread.Execute;
    begin
    poskjgfrm.wangluozhuangtai(FchannelStr,FcolInt);
    end;constructor TPingIPThread.Create(par_channelStr:string;Par_colInt:integer);
    begin
         FchannelStr:=par_channelStr;
         FcolInt:=Par_colInt;
         FreeOnTerminate:=true;
         inherited Create(True);
    end;
      

  2.   

    我只是想用Windows 的 API 即利用CreatThread函数,不想创建线程对象!在主程序中有一个函数TestThread,然后就用CreateThread(nil,0,@TForm1.TestThread,nil,0,Thread1);就可以创建线程!但我不知道怎么把参数传进线程中!
      

  3.   


    var
      Form1: TForm1;
      ThreadHandle: THandle;implementation{$R *.DFM}function ThreadFunc(Info: Pointer): Integer; stdcall;
    begin
      Form1.Edit1.Text := 'Hello from the thread!';
      Sleep(1000);
      ExitThread(4);
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      ThreadId1: DWORD;
    begin
      ThreadHandle := CreateThread(nil, 0, @ThreadFunc, nil, 0, ThreadId1);
    end;
      

  4.   

    CreateThread(
    lpThreadAttributes: Pointer; {a pointer to a TSecurityAttributes structure}
    dwStackSize: DWORD; {initial stack size of the thread in bytes}
    lpStartAddress: TFNThreadStartRoutine; {address of the thread routine}
    lpParameter: Pointer;  {argument of the new thread}
    dwCreationFlags: DWORD;  {creation flags}
    var lpThreadId: DWORD {address of the thread id}): THandle; {returns the handle of the new thread}具体祥见MSDN
      

  5.   

    那个函数只有一个pointer参数!!!!!你在createthread函数中传递lpParameter: Pointer;会交给线程处理函数
      

  6.   

    to : del_c_sharp(头大中......)
    能否举个简单例子吗?谢谢
      

  7.   

    http://www.csdn.net/expert/topic/1034/1034176.xml?temp=.2848322
      

  8.   

    wzrlover(wzrlover)  的例子可以阿:var
      Form1: TForm1;
      ThreadHandle: THandle;implementation{$R *.DFM}function ThreadFunc(Info: Pointer): Integer; stdcall;
    begin
      Form1.Edit1.Text := 'Hello from the thread!';
      Sleep(1000);
      ExitThread(4);
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      ThreadId1: DWORD;
    begin
      ThreadHandle := CreateThread(nil, 0, @ThreadFunc, nil, 0, ThreadId1);
    end;