2012-01-27 3 views
1

У меня есть образец кода, который я пытаюсь понять в delphi, может ли кто-нибудь объяснить это ниже, я знаю, что он создает и устанавливает события, но я пытаюсь понять, почему (nil, true, false, 'pishu ') Я хочу знать значение nil, true, false и слово в перевернутой запятой, кажется, я могу написать любое слово там.обработка событий в delphi

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

MSDN - ваш друг, когда дело доходит до вопросов документации API. See this for answers to your question about CreateEvent.

+2

Хотя это теоретически может ответить на вопрос, [было бы предпочтительно] (http://meta.stackexchange.com/q/8259) включить сюда основные части ответа и предоставить ссылку для справки. – jjnguy

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. 

Это объясняет, почему вы можете ввести почти ничего, как «слова с кавычками» (The lpName).

Для получения дополнительной информации вы можете ознакомиться с документацией веб-сайта MSDN по адресу CreateEvent .

Смежные вопросы