Discussion:
Open one time alone form in mdi application
(too old to reply)
Cooper
2010-04-17 17:42:23 UTC
Permalink
Hello,
I have MDI application; and a form MYWIN. I want to do in mode that when
MYWIN is opened not is possible to open MYWIN again.
I have thinked about use a boolean variable that i define as global and set
a false on create of main form; and when open MYWIN i set it on true.
Problem is: when i close MYWIN this variable continue to be true. Can i can
to so in mode to update this variabile to false on close of MYWIN?
Otherwise, is possible use other better solution that this?
Thanks you very much.
Cooper.
Jamie
2010-04-18 10:14:00 UTC
Permalink
Post by Cooper
Hello,
I have MDI application; and a form MYWIN. I want to do in mode that when
MYWIN is opened not is possible to open MYWIN again.
I have thinked about use a boolean variable that i define as global and
set a false on create of main form; and when open MYWIN i set it on true.
Problem is: when i close MYWIN this variable continue to be true. Can i
can to so in mode to update this variabile to false on close of MYWIN?
Otherwise, is possible use other better solution that this?
Thanks you very much.
Cooper.
Instead of directly calling the "MYWIN" form to create or display it,
create a function that can check for the existence of this form in the
parent list..

Function OpenMyWIN:Boolean;
Var
C:TComponent;
Begin
C:= TheOwnerForm.FindComponent('MYWIN');
If Assigned(C) Then MYWIN.Show else
MYWIN := TMyWIN.Create(TheOwnerForm);
End;

When ever the form is closed some how, it should detach itself from the
owner.. Thus , it'll be created once again..

Of course, this requires that it has an owner form, but that shouldn't
be much of an issue.

Jamie.
Maarten Wiltink
2010-04-18 09:09:10 UTC
Permalink
Post by Cooper
I have MDI application; and a form MYWIN. I want to do in mode that
when MYWIN is opened not is possible to open MYWIN again.
I have thinked about use a boolean variable that i define as global
and set a false on create of main form; and when open MYWIN i set it
on true. Problem is: when i close MYWIN this variable continue to be
true. Can i can to so in mode to update this variabile to false on
close of MYWIN? Otherwise, is possible use other better solution that
this?
To start with a side avenue, from the kind of errors in this message
I'm guessing that you are now writing in English instead of relying on
Google Translate. It's not perfect, but a _lot_ easier to understand.

Forms have an OnClose event. It does exactly what you'd expect. Look
it up in the help. Take special notice of its parameters. They don't
all go in the direction you'd expect.

Think about what you want to know from this Boolean variable: that the
form exists. There are probably at least two other places that keep
not just that tidbit, but exact references to the form, if it exists.
Screen.Forms even removes its reference if the form is destroyed; the
global form variable that Delphi puts in every form unit for you, you
have to clear yourself. This is just a slight variation on what you
asked for.

Groetjes,
Maarten Wiltink
BRoberts
2010-04-22 07:07:43 UTC
Permalink
Post by Cooper
Hello,
I have MDI application; and a form MYWIN. I want to do in mode that when
MYWIN is opened not is possible to open MYWIN again.
I have thinked about use a boolean variable that i define as global and
set a false on create of main form; and when open MYWIN i set it on true.
Problem is: when i close MYWIN this variable continue to be true. Can i
can to so in mode to update this variabile to false on close of MYWIN?
Otherwise, is possible use other better solution that this?
Thanks you very much.
Cooper.
For neatness one can use a Class method:

tForm1 = class (tForm)
. . .
private
class function isUnique : boolean;
. . .
public
. . .
constructor Create (aOwner : tComponent); override;
destructor Destroy; override;
. . .
end;


var isCreated : boolean = false;

class function tForm1.isUnique : boolean;

begin
Result := not isCreated;
end;

constructor tForm1.Create (aOwner : tComponent); override;

begin
if isUnique
then begin
inherited;
isCreated := True;
end;
else raise Exception.Create ('already created'); // or use abort
end;

destructor tForm1.Destroy;

begin
isCreated := False;
inherited;
end;

Loading...