title: Comparing a pointer to function's value in Delphi
body: <p>How can I compare the <strong>value</strong> of a variable that contains a pointer to a function with a function address?</p>
  
  <p>I'm maintaining some code, and it is failing in Delphi 2007.  The declaration is:</p>
  
  <pre><code>var
    EditorFrameWindow: Function: HWnd Of Object = Nil;
  </code></pre>
  
  <p>In a form activation, I've got:</p>
  
  <pre><code>procedure TEditForm.FormActivate(Sender: TObject);
  begin
    EditorFrameWindow := GetFrameWindow;
  end;
  </code></pre>
  
  <p>And in the form deactivation I've got:</p>
  
  <pre><code>procedure TEditForm.FormDeactivate(Sender: TObject);
  begin
    if EditorFrameWindow = GetFrameWindow then
      EditorFrameWindow := nil;
  end;
  </code></pre>
  
  <p>So what is happening is that the form is being deactivated twice, and it is failing as nothing else got activated. The FormDeactivate is called, it matches, and the EditorFrameWindow global is set to (nil,nil) (according to the debugger). Then it is being called again, and the function stored in the variable is called, but of course there isn't one stored so it jumps through nil and creates an exception. </p>
  
  <p>What should I do to stop this happening? (The framework has been changed to a tabbed system, so the operation probably changed.)</p>