LeTay
asked on
Detect existence of an object
Is there an easy and elegant way to detect if a specific object has been created ?
In my case, objects to verify are forms.
Thanks
In my case, objects to verify are forms.
Thanks
ASKER
Well in fact, the component I am trying to find if it still exists is that Form1, not a component inside it
So ?
So ?
So you can check if it's assigned by
If Assigned(Form1)
or using it's name
var
Form: TForm;
begin
Form := Application.FindComponent('Form1') as TForm;
if Assigned(Form) then
Form.Show
else
{ can't find it, so maybe you want to create it }
ASKER
My idea was something like this, but it is not very elegant (I know that my forms have their Tag >= 0)
function FormExists(F:TForm):boolea n;
begin
try
Result := (F.Tag >= 0);
except
Result := False;
end;
end;
function FormExists(F:TForm):boolea
begin
try
Result := (F.Tag >= 0);
except
Result := False;
end;
end;
Form can be found using by Name or using Forms Caption + Class name:
or using Application as form owner:
if FindWindow('TForm1', 'FormsCaption') <> 0 then .... // form exists
or using Application as form owner:
...Application.FindComponent('Form1')...
ASKER
Is it faster than "my" method ?
I have to check existence of around a hundred forms ...
I have to check existence of around a hundred forms ...
ASKER
Also, does the findcomponent return "false" if the form has not been created ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Many thanks, this works fine
Open in new window
if you need to serch on whole form:
Open in new window
or
Open in new window