Is the form already open?

Viewed 6039

I have been using the following code to check if a form already exists:

function FormExists(apForm: TObject): boolean;
var i: Word;
begin
  Result := False;
  for i := 0 to Application.ComponentCount-1 do
    if Application.Components[i] = apForm then begin
      Result := True;
      Break;
    end;
end;

I got it some years ago from a project I participated in. It was one of my first Delphi projects.

It works.

But this week I got wandering if there is a better, faster way to do this.

2 Answers
Related