我在线程单元中调用if waitforsingleobject(hmutex,infinite)=wait_object_0 then
编译的时候显示是[Error] Unit3.pas(38): Undeclared identifier: 'waitforsingleobject'
但是在mainform中没问题,求指点!

解决方案 »

  1.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Unit2, Unit3;type
      TForm1 = class(TForm)
        ListBox1: TListBox;
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure ListboxShow;
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;
      MyArray: array[1..128] of integer;
      CS: TRTLCriticalSection;
    implementation{$R *.dfm}
    procedure TForm1.ListboxShow;
    var
      i: integer;
    begin
      for i := 1 to 128 do
        listbox1.Items.Add(inttostr(Myarray[i]));
    end;procedure TForm1.Button1Click(Sender: TObject);
    begin
      //iniTializecriticalsection(CS);
     // if waitforsingleobject(hmutex,infinite)=wait_object_0 then
      //begin
      TThread1.Create(false);
      Thread2.Create(false);
      listboxshow;
    end;end.
      

  2.   

    unit Unit2;interfaceuses
      Classes;type
      TThread1 = class(TThread)
      private
        { Private declarations }
      protected
        procedure Execute; override;
      end;implementation
    uses unit1;{ Important: Methods and properties of objects in visual components can only be
      used in a method called using Synchronize, for example,      Synchronize(UpdateCaption);  and UpdateCaption could look like,    procedure TThread1.UpdateCaption;
        begin
          Form1.Caption := 'Updated in a thread';
        end; }{ TThread1 }procedure TThread1.Execute;
    var
      i: integer;
    begin
      if waitforsingleobject(hmutex,infinite)=wait_object_0 then
      begin
      //EnterCriticalSection(CS);
      for i := 1 to 128 do
      begin
        unit1.MyArray[i] := i-1;
        sleep(5);
      end;//leavecriticalsection(CS);
      end;{ Place thread code here }
    end;end.
      

  3.   


    unit Unit3;interfaceuses
      Classes;type
      Thread2 = class(TThread)
      private
        { Private declarations }
      protected
        procedure Execute; override;
      end;implementation
    uses unit1;{ Important: Methods and properties of objects in visual components can only be
      used in a method called using Synchronize, for example,      Synchronize(UpdateCaption);  and UpdateCaption could look like,    procedure Thread2.UpdateCaption;
        begin
          Form1.Caption := 'Updated in a thread';
        end; }{ Thread2 }procedure Thread2.Execute;
    var
      i: integer;
    begin
      if waitforsingleobject(hmutex,infinite)=wait_object_0 then
      begin
      for i := 1 to 128 do
      begin
        Myarray[i] :=  i;
        sleep(5);
      end;
      end;{ Place thread code here }
    end;end.
      

  4.   

    unit2和unit3里的
    uses
      Classes;改成uses
      Windows, Classes;