Board index » delphi » how do I do this without a timer???

how do I do this without a timer???

Hi All,

   I'm writing a small program, actually it's a text editor (yes I know
that there's 1000's of them).

   Anyway I have this problem where my editor (program) has a tmainmenu
with a "Window" menu and under it it has "tile", "cascade" and "arrange
all". Ok, so when the user opens a file (or a new file), I add a new
menuitem to the window menu, with the filename (or "untitled1" etc).
This all works fine. The problem is that when the user wants to close a
file (which are all child windows), that then I want to release the
window, not just close it. The problem is that when I release the child
form, I can't figure out how to tell the main form that the child wants
to close.

   Well actually that's not quite true... I did find a way, which
involves me making a 3rd unit with a boolean var in the interface
section. Then both the main form and the child form use this new unit
and when the child form wants to close it simply sets the boolean var
to true and is not allowed to close. Then I use a timer in the main
form to check the boolean var, and when it's true it then sets it to
false (to stop the routine from running twice) then it releases the
child form and deletes the entry from the "Window" menu.

  This all works. However my question is: how do achieve the same thing
*without* using a timer??? I assume that the answer involves using
teventnotfiy but I'm just guessing and I don't know anything about it.
(maybe that's obvious from this question??? :-))) BTW - I'm using
Delphi 5.0 Std (sp1) - and so I don't have access to the code that
comes with the pro version. Can anyone please give me a little
***sample code*** to show me how it's done???

Regards,
      Peter Williams  :)))

Sent via Deja.com http://www.deja.com/
Before you buy.

 

Re:how do I do this without a timer???


Hi,

I don't see any problem.

TEditForm = class ;

TMainForm = class( TFomr )
  ...
  public
    procedure AddToWindowList( AForm : TEditForm );
    procedure DeleteFromWindowList( AForm : TEditForm );
end;

...

TEditForm.FormCreate(..)
begin
   ...
   MainForm.AddToWindowList( Self );
end;

...

TEditForm.FormDestroy(...)
begin
   ...
   MainForm.DeleteFromWindowList( Self );
end;

James.

Re:how do I do this without a timer???


Hi James,

    I probably wasn't making the problem clear. I have a main form and
a child form. I can create and release child forms without any problem,
however then main form has on it a tmainmenu with a "window" menuitem
and under it there is an entry for the filename of the file which is
being edited in the child form. The problem is that I want the child
form to delete the entry in the tmainmenu containing the entry for the
child form and of course the child form can't access the tmainmenu
because it's on the main form, and the main form uses the child form.
My work-around involves using a 3rd form with a boolean var and then
having a timer on the main form which tests this var (this involves
then the child form not closing itself but flaging that it wants to be
released by the main form which first removes the tmainmenu entry then
releases the active child form). But this seems like a waste of a timer
(and CPU time). So is there a better way to do it???

   Please post sample code with your reply(s). Thanks.

Regards,
      Peter Williams  :)))

In article <AoYU5.12794$3u1.2969...@news3.rdc1.on.home.com>,
  "James Zhou" <zhou8...@home.com> wrote:

Quote
> Hi,

> I don't see any problem.

> TEditForm = class ;

> TMainForm = class( TFomr )
>   ...
>   public
>     procedure AddToWindowList( AForm : TEditForm );
>     procedure DeleteFromWindowList( AForm : TEditForm );
> end;

> ...

> TEditForm.FormCreate(..)
> begin
>    ...
>    MainForm.AddToWindowList( Self );
> end;

> ...

> TEditForm.FormDestroy(...)
> begin
>    ...
>    MainForm.DeleteFromWindowList( Self );
> end;

> James.

Sent via Deja.com http://www.deja.com/
Before you buy.

Re:how do I do this without a timer???


Hi Peter

AFAIK, In D4 anyway, if you have an MDI application, on the form that is the
MDI form, you have an option in the form properties to set a window menu, if
you set that to your window, or whatever you have called it, it will
maintain a list of all the MDI children windows automatically. As and when
you create and destroy those child windows they appear and disappear without
you having to do anything. This is by far the simplest solution assuming
your version of Delphi does it.

Hope this helps

Rick

Quote
"Peter Williams" <pw...@ausi.com> wrote in message

news:901ioj$oma$1@nnrp1.deja.com...
Quote
> Hi All,

>    I'm writing a small program, actually it's a text editor (yes I know
> that there's 1000's of them).

>    Anyway I have this problem where my editor (program) has a tmainmenu
> with a "Window" menu and under it it has "tile", "cascade" and "arrange
> all". Ok, so when the user opens a file (or a new file), I add a new
> menuitem to the window menu, with the filename (or "untitled1" etc).
> This all works fine. The problem is that when the user wants to close a
> file (which are all child windows), that then I want to release the
> window, not just close it. The problem is that when I release the child
> form, I can't figure out how to tell the main form that the child wants
> to close.

>    Well actually that's not quite true... I did find a way, which
> involves me making a 3rd unit with a boolean var in the interface
> section. Then both the main form and the child form use this new unit
> and when the child form wants to close it simply sets the boolean var
> to true and is not allowed to close. Then I use a timer in the main
> form to check the boolean var, and when it's true it then sets it to
> false (to stop the routine from running twice) then it releases the
> child form and deletes the entry from the "Window" menu.

>   This all works. However my question is: how do achieve the same thing
> *without* using a timer??? I assume that the answer involves using
> teventnotfiy but I'm just guessing and I don't know anything about it.
> (maybe that's obvious from this question??? :-))) BTW - I'm using
> Delphi 5.0 Std (sp1) - and so I don't have access to the code that
> comes with the pro version. Can anyone please give me a little
> ***sample code*** to show me how it's done???

> Regards,
>       Peter Williams  :)))

> Sent via Deja.com http://www.deja.com/
> Before you buy.

Re:how do I do this without a timer???


Maybe I'm misunderstanding the problem, but why can't you just handle the
OnClose event of the MDI child form in your main form?

procedure TMainForm.MakeNewWindow;
with TChildMdiForm.Create do
begin
    OnClose := MdiFormClosed;
    // add new window to menu...
end;

procedure TMainForm.MidFormClosed;
begin
    // remove window from menu...
end;

Quote
"Peter Williams" <pw...@ausi.com> wrote in message

news:901ioj$oma$1@nnrp1.deja.com...
Quote
> Hi All,

>    I'm writing a small program, actually it's a text editor (yes I know
> that there's 1000's of them).

>    Anyway I have this problem where my editor (program) has a tmainmenu
> with a "Window" menu and under it it has "tile", "cascade" and "arrange
> all". Ok, so when the user opens a file (or a new file), I add a new
> menuitem to the window menu, with the filename (or "untitled1" etc).
> This all works fine. The problem is that when the user wants to close a
> file (which are all child windows), that then I want to release the
> window, not just close it. The problem is that when I release the child
> form, I can't figure out how to tell the main form that the child wants
> to close.

>    Well actually that's not quite true... I did find a way, which
> involves me making a 3rd unit with a boolean var in the interface
> section. Then both the main form and the child form use this new unit
> and when the child form wants to close it simply sets the boolean var
> to true and is not allowed to close. Then I use a timer in the main
> form to check the boolean var, and when it's true it then sets it to
> false (to stop the routine from running twice) then it releases the
> child form and deletes the entry from the "Window" menu.

>   This all works. However my question is: how do achieve the same thing
> *without* using a timer??? I assume that the answer involves using
> teventnotfiy but I'm just guessing and I don't know anything about it.
> (maybe that's obvious from this question??? :-))) BTW - I'm using
> Delphi 5.0 Std (sp1) - and so I don't have access to the code that
> comes with the pro version. Can anyone please give me a little
> ***sample code*** to show me how it's done???

> Regards,
>       Peter Williams  :)))

> Sent via Deja.com http://www.deja.com/
> Before you buy.

Re:how do I do this without a timer???


Hi Rhys,

    This is probably the solution I'll go with. I didn't know that I
could do this. Thanks.

Regards,
      Peter Williams  :)))

In article <902nbc$g1...@taliesin.netcom.net.uk>,
  "Rhys Parsons" <r...@rgparsons.freeserve.co.uk> wrote:

Quote
> Maybe I'm misunderstanding the problem, but why can't you just handle
the
> OnClose event of the MDI child form in your main form?

> procedure TMainForm.MakeNewWindow;
> with TChildMdiForm.Create do
> begin
>     OnClose := MdiFormClosed;
>     // add new window to menu...
> end;

> procedure TMainForm.MidFormClosed;
> begin
>     // remove window from menu...
> end;

> "Peter Williams" <pw...@ausi.com> wrote in message
> news:901ioj$oma$1@nnrp1.deja.com...
> > Hi All,

> >    I'm writing a small program, actually it's a text editor (yes I
know
> > that there's 1000's of them).

> >    Anyway I have this problem where my editor (program) has a
tmainmenu
> > with a "Window" menu and under it it has "tile", "cascade"
and "arrange
> > all". Ok, so when the user opens a file (or a new file), I add a new
> > menuitem to the window menu, with the filename (or "untitled1" etc).
> > This all works fine. The problem is that when the user wants to
close a
> > file (which are all child windows), that then I want to release the
> > window, not just close it. The problem is that when I release the
child
> > form, I can't figure out how to tell the main form that the child
wants
> > to close.

> >    Well actually that's not quite true... I did find a way, which
> > involves me making a 3rd unit with a boolean var in the interface
> > section. Then both the main form and the child form use this new
unit
> > and when the child form wants to close it simply sets the boolean
var
> > to true and is not allowed to close. Then I use a timer in the main
> > form to check the boolean var, and when it's true it then sets it to
> > false (to stop the routine from running twice) then it releases the
> > child form and deletes the entry from the "Window" menu.

> >   This all works. However my question is: how do achieve the same
thing
> > *without* using a timer??? I assume that the answer involves using
> > teventnotfiy but I'm just guessing and I don't know anything about
it.
> > (maybe that's obvious from this question??? :-))) BTW - I'm using
> > Delphi 5.0 Std (sp1) - and so I don't have access to the code that
> > comes with the pro version. Can anyone please give me a little
> > ***sample code*** to show me how it's done???

> > Regards,
> >       Peter Williams  :)))

> > Sent via Deja.com http://www.deja.com/
> > Before you buy.

Sent via Deja.com http://www.deja.com/
Before you buy.

Other Threads