Nani
Nani

Reputation: 123

Difference between @H and @H[0]

I have

 var H: array of THandle;

then in a loop I create multiple threads, and assign thread handles to the elements of H, and then wait on them. Passing @H[0] as the 2nd parameter to WFMO below works.

WaitForMultipleObjects(Length(H), @H[0], True, INFINITE) <-- Works

But passing @H as below Fails with WAIT_FAILED. GetLastError returns "Invalid Handle".

WaitForMultipleObjects(Length(H), @H, True, INFINITE)  <--- Fails.

Why is @H different from @H[0] ?

Upvotes: 8

Views: 303

Answers (1)

zed
zed

Reputation: 877

  1. Because it is a dynamic array, H is already a pointer and it points to the first element, so
  2. @H[0] is the same as H - pointer to the first element
  3. and now @H is equals to @@H[0] - pointer to pointer to the first element.

Upvotes: 8

Related Questions