kryticrecte
kryticrecte

Reputation: 377

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.

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.

Upvotes: 1

Views: 3242

Answers (2)

Ken White
Ken White

Reputation: 125749

CreateEvent takes several parameters. It's defined on MSDN as 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).

For more information, you can see the MSDN web site's documentation on CreateEvent here.

Upvotes: 4

Glenn1234
Glenn1234

Reputation: 2582

MSDN is your friend when it comes to API documentation questions .See this for answers to your question about CreateEvent.

Upvotes: 0

Related Questions