Comparing a pointer to a function value in Delphi

How to compare value a variable containing a pointer to a function with the address of the function?

I support some code and it does not work in Delphi 2007. Declaration:

var
  EditorFrameWindow: Function: HWnd Of Object = Nil;

In the form activation, I have:

procedure TEditForm.FormActivate(Sender: TObject);
begin
  EditorFrameWindow := GetFrameWindow;
end;

And in the deactivation form, I have:

procedure TEditForm.FormDeactivate(Sender: TObject);
begin
  if EditorFrameWindow = GetFrameWindow then
    EditorFrameWindow := nil;
end;

So what happens is that the form is deactivated twice, and it fails because nothing else is activated. Called FormDeactivate, it matches, and global EditorFrameWindow - (nil, nil) (according to the debugger). Then it is called again, and the function stored in the variable is called, but, of course, it is not, so it jumps over nil and throws an exception.

What should I do to stop this? (The frame was changed to a tabbed system, so the operation probably changed.)

+5
2

Would

procedure TEditForm.FormDeactivate(Sender: TObject);
begin
  if Assigned(EditorFrameWindow) and (EditorFrameWindow = GetFrameWindow) then
    EditorFrameWindow := nil;
end;

?

Edit:

, . , , , , . , , reset .

, ​​ , TMethod. - :

procedure TEditForm.FormDeactivate(Sender: TObject);
begin
  if (TMethod(EditorFrameWindow).Code = @TForm1.GetFrameWindow)
    and (TMethod(EditorFrameWindow).Data = Self)
  then
    EditorFrameWindow := nil;
end;
+14

. , . Delphi , :

if @EditorWindowMethod = @TEditForm.GetFrameWindow then
  EditorWindowMethod := nil;

, EditorWindowMethod GetFrameWindow TEditForm. , EditorWindowMethod Self. , , TMethod, Mghie answer . ( , , , , . GetFrameWindow, .)

@ , . , . EditorWindowMethod GetFrameWindow. , , EditorWindowMethod. , , EditorWindowMethod, .

, . , GetFrameWindow.

+8

All Articles