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.
Just call Show method on the instance. You can check Form. Visible property to check if the form open at the moment.
You can use Form. IsActive property.
There is a login from when I enter a password and username and then the page goes directly to another page named form2. Now go to Solution Explorer and select your project and right-click on it and select a new Windows Forms form and provide the name for it as form2. Now click the submit button and write the code.
This is also the type of application that small and medium enterprises/companies need. In addition, just using components like Telerik UI or DevExpress, WinForm can create modern, dreamlike, long-lasting interfaces. flowery flax. With these advantages, WinForm still lives well and lives well.
You can use Screen.Forms for that instead. It lessens the items you're iterating through:
function FormExists(apForm: TForm): boolean;
var
i: Word;
begin
Result := False;
for i := 0 to Screen.FormCount - 1 do
if Screen.Forms[i] = apForm then
begin
Result := True;
Break;
end;
end;
However, it's worth noting that if you have apForm
already, you know it exists and there's no need to be searching for it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With