简体   繁体   English

delphi中的事件处理

[英]event handling in delphi

I got a sample of code im trying to understand in delphi,can anyone explain this means below,i know it creates and sets events but im trying to understand why the (nil,true,false,'pishu') i want to know the significance of the nil,true,false and the word in inverted comma's it seems i can write any word in there. 我有一个代码示例试图在delphi中理解,有人可以在下面解释这个意思,我知道它创建并设置了事件,但是我试图理解为什么我想知道(nil,true,false,'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.

CreateEvent takes several parameters. CreateEvent需要几个参数。 It's defined on MSDN as HANDLE CreateEvent( LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPTSTR lpName) . 它在MSDN上定义为HANDLE CreateEvent( LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState, LPTSTR lpName) The parameters are: 参数为:

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. 

This explains why you can type almost anything as the "word with inverted commas" (the lpName ). 这解释了为什么您可以输入几乎所有内容作为“带反逗号的单词”( lpName )。

For more information, you can see the MSDN web site's documentation on CreateEvent here. 有关更多信息,您可以在此处查看MSDN网站上有关CreateEvent的文档。

MSDN is your friend when it comes to API documentation questions . 关于API文档问题,MSDN是您的朋友。 See this for answers to your question about CreateEvent. 请参阅此以获取有关CreateEvent的问题的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM