德尔福的事件处理

时间:2012-01-27 01:59:48

标签: delphi events

我有一个代码示例我试图在delphi中理解,任何人都可以在下面解释这个意思,我知道它创建和设置事件但我试图理解为什么(零,真,假,'pishu')我想要要知道nil,true,false和倒置逗号中的单词的意义,似乎我可以在那里写任何单词。

var
  Form1: TForm1;
  h:thandle;
  st:string;
  fopen:textfile;
  countstr:integer;
implementation

{$R *.dfm}


procedure TForm1.Button2Click(Sender: TObject);
begin
   setEvent(h);
   CloseHandle(h);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
h:=createevent(nil,true,false,'pishu');
resetevent(h);              
end;

end.

procedure TForm1.Button1Click(Sender: TObject);
begin
h:=createevent(nil,true,true,'pishu');
 waitforsingleobject(h,infinite); 

image1.Canvas.Brush.Color:=clblack;
image1.Canvas.Ellipse(random(image1.Width-100),random(image1.Width),random(image1.Width),random(image1.Width));
image1.Canvas.Brush.Color:=clyellow;
image1.Canvas.Ellipse(random(image1.Width-100),random(image1.Width),random(image1.Width),random(image1.Width));
image1.Canvas.Brush.Color:=clblue;
image1.Canvas.Ellipse(random(image1.Width-100),random(image1.Width),random(image1.Width),random(image1.Width));
image1.Canvas.Brush.Color:=clred;
image1.Canvas.Ellipse(random(image1.Width-100),random(image1.Width),random(image1.Width),random(image1.Width));
image1.Canvas.Brush.Color:=clgreen;
image1.Canvas.Ellipse(random(image1.Width-100),random(image1.Width),random(image1.Width),random(image1.Width));


//рисуем квадраты
image1.Canvas.Brush.Color:=clblack;
image1.Canvas.Rectangle(random(image1.Width-100),random(image1.Width),random(image1.Width),random(image1.Width));
image1.Canvas.Brush.Color:=clyellow;
image1.Canvas.Rectangle(random(image1.Width-100),random(image1.Width),random(image1.Width),random(image1.Width));
image1.Canvas.Brush.Color:=clblue;
image1.Canvas.Rectangle(random(image1.Width-100),random(image1.Width),random(image1.Width),random(image1.Width));
image1.Canvas.Brush.Color:=clred;
image1.Canvas.Rectangle(random(image1.Width-100),random(image1.Width),random(image1.Width),random(image1.Width));
image1.Canvas.Brush.Color:=clgreen;
image1.Canvas.Rectangle(random(image1.Width-100),random(image1.Width),random(image1.Width),random(image1.Width));

CloseHandle(h);
end;

end.

2 个答案:

答案 0 :(得分:4)

CreateEvent需要几个参数。它在MSDN上定义为HANDLE CreateEvent( LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPTSTR lpName)。参数是:

lpEventAttributes
==================
Ignored. Must be NULL. 

bManualReset
============
Boolean that specifies whether a manual-reset or auto-reset 
event object is created. If TRUE, then you must use the 
ResetEvent function to manually reset the state to nonsignaled. 
If FALSE, the system automatically resets the state to nonsignaled 
after a single waiting thread has been released. 

bInitialState
=============
Boolean that specifies the initial state of the event object. 
If TRUE, the initial state is signaled; otherwise, it is nonsignaled. 

lpName
======
Pointer to a null-terminated string that specifies the name of the 
event object. The name is limited to MAX_PATH characters and can contain 
any character except the backslash path-separator character (\). Name 
comparison is case sensitive.

If lpName matches the name of an existing named event object, the bManualReset 
and bInitialState parameters are ignored because they have already been set by 
the creating process.

If lpName is NULL, the event object is created without a name.

If lpName matches the name of an existing semaphore, mutex, waitable timer, 
job, or file-mapping object, the function fails and the GetLastError function 
returns ERROR_INVALID_HANDLE. This occurs because these objects share the same 
name space. 

这就解释了为什么你可以输入几乎任何东西作为带有引号的"单词" (lpName)。

有关详情,请参阅CreateEvent上的MSDN网站文档 这里。

答案 1 :(得分:0)

关于API文档问题,MSDN是您的朋友。See this for answers to your question about CreateEvent.

相关问题