Board index » delphi » Checking existence...

Checking existence...

Hi there!

Have a lil problem. I need to check the existence of a particular TForm
object, and depending on it allow or deny the creation of the same TForm
object once again.

Thanks

 

Re:Checking existence...


Hi,

you can do this,

If form_one = NIL then
  application.createform(tform_one,form_one);

And in the FormClose event put

form_one := NIL;

On Tue, 16 May 2000 18:31:27 +0200, "Andrius Belych"

Quote
<andrej.bel...@nospamvinita.lt> wrote:
>Hi there!

>Have a lil problem. I need to check the existence of a particular TForm
>object, and depending on it allow or deny the creation of the same TForm
>object once again.

>Thanks

Re:Checking existence...


Here is a function that I use in all my main forms. It allows you to pass it
the form name. That's the name you give the form either in design mode or at
run-time.

function TMain.IsOpen(FormName: string): boolean;
var
 x: integer;

begin
 result := false;
 for x := 0 to Screen.FormCount-1 do
   if AnsiCompareText(Screen.Forms[x].Name,FormName) = 0 then
     result := true;
end;

HTH
Woody

Quote
"Andrius Belych" <andrej.bel...@nospamvinita.lt> wrote in message

news:392177df@news.takas.lt...
Quote
> Hi there!

> Have a lil problem. I need to check the existence of a particular TForm
> object, and depending on it allow or deny the creation of the same TForm
> object once again.

> Thanks

Re:Checking existence...


The following function returns an existing TForm1 or creates one if not
found:

function GetForm: TForm1;
begin
  for i := 0 to Screen.FormCount - 1 do
    if Screen.Forms[i] is TForm1 then
    begin
      Result := TForm1(Screen.Forms[i]);
      Exit;
    end;
  Result := TForm1.Create(Application);
end;

"Andrius Belych" <andrej.bel...@nospamvinita.lt> schreef in bericht
news:392177df@news.takas.lt...

Quote
> Hi there!

> Have a lil problem. I need to check the existence of a particular TForm
> object, and depending on it allow or deny the creation of the same TForm
> object once again.

> Thanks

Re:Checking existence...


Many thanks to all of u, fellas.

Regards

Quote
Andrius Belych <andrej.bel...@nospamvinita.lt> wrote in message

news:392177df@news.takas.lt...
Quote
> Hi there!

> Have a lil problem. I need to check the existence of a particular TForm
> object, and depending on it allow or deny the creation of the same TForm
> object once again.

> Thanks

Re:Checking existence...


JRS:  In article <si33b9o6rj...@corp.supernews.com> of Tue, 16 May 2000
13:03:12 seen in news:alt.comp.lang.borland-delphi, Woody

Quote
<woody....@ih2000.net> wrote:
>Here is a function that I use in all my main forms. It allows you to pass it
>the form name. That's the name you give the form either in design mode or at
>run-time.

>function TMain.IsOpen(FormName: string): boolean;
>var
> x: integer;

>begin
> result := false;
> for x := 0 to Screen.FormCount-1 do
>   if AnsiCompareText(Screen.Forms[x].Name,FormName) = 0 then
>     result := true;
>end;

Please respond *after* what you quote, according to agreed norms.

You can save on average about half the time taken by that loop in "true"
cases by breaking out of the loop or function as soon as a match is
found.

--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
 <URL: http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
 <URL: ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ;
 <URL: http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b. mFAQ.

Re:Checking existence...


There is a simple thing i do that works very nice to insure its reliable
each time and that is in the
bottom of each unit that contains a for you do this.
Begin
  formsOfThisUnit := Nil;
end.
 THis is assuming that these forms are run time type..
 and then when you lanch the form you do this.
if formXXX? = Nil Then formXXX? := TformXXX?.Create(Application);
  FormXXX?.ShowModal;
  FormXXX?.Free;
 FormXXX? : = Nil;;
----
 On other note that you should be aware of...
 in the Forms creation event the FormXXX? will still be Nil.
to fix any possible access problems you can Set the FormXXX then..
FormXXX? := TformXXX?(Self;)

 if you do not use the Form.ShowModal and use SHOW only then in the Destroy
event you
can clear it..
 FormXXX? := Nil;
self is always used while with in the Object so modifying the Variable will
not hurt.

Quote
Andrius Belych wrote:
> Hi there!

> Have a lil problem. I need to check the existence of a particular TForm
> object, and depending on it allow or deny the creation of the same TForm
> object once again.

> Thanks

Re:Checking existence...


I am sorry if my etiquette in regard to where I respond is different,
however, it makes much more sense for me to read the answer because they
already know the question. No need to scroll through a possible long quote
to get to that which you seek. If a post is short, I usually leave it on the
bottom in case they want to refresh their memory or for those, like myself,
who clear all messages after reading them. On longer posts, I only respond
with an answer. Therefore, it is much easier to have my default set to the
top of the response. I hate excessive quoting, don't you?

Please, I'm not starting a flame war on NG Etq., just expressing my opinion.
I apologize if I offend anyone over this. Any more discussions about it
should be moved to non-tech.

Woody

Re:Checking existence...


"Dr John Stockton" <j...@merlyn.demon.co.uk> wrote in message
news:ReWY7vAQqnI5Ewvq@merlyn.demon.co.uk...

Quote

> You can save on average about half the time taken by that loop in "true"
> cases by breaking out of the loop or function as soon as a match is
> found.

Oh yeah, and thanks for the tip. Don't know how I missed the obvious....

Woody

Other Threads