我在线程单元中调用if waitforsingleobject(hmutex,infinite)=wait_object_0 then
编译的时候显示是[Error] Unit3.pas(38): Undeclared identifier: 'waitforsingleobject'
但是在mainform中没问题,求指点!
编译的时候显示是[Error] Unit3.pas(38): Undeclared identifier: 'waitforsingleobject'
但是在mainform中没问题,求指点!
解决方案 »
- 如何MDI的主窗体的背景放入一个TWebBrowser
- 进销存打单网格控件用什么最好?
- 如何快速的加载Access表里的数据?
- 怎样让DBgrid可以做到单元格合并?
- 第三方组件,有source目录和文件,是否可以将有些英文的内容改成中文的?
- 用Delphi做VPN那样的软件的问题
- 如何解决数据更新时出错?
- application?HWND?
- 从哪儿能够找到关于Delphi多线程变量互斥/共享访问的资料?
- 哪位大师能教我一下怎样调用API函数,如:midiOutGetDevCaps...
- DynamicSkinForm 控件使用请教一下用过这个控件的前辈,指点一二,谢谢
- 怎样把字符串转换为十六进制
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.
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.
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.
uses
Classes;改成uses
Windows, Classes;