Main form title (sometimes) incorrect on exit/close MDI child form

Posted on 2006-04-12
Last Modified: 2010-04-05
An application uses MDI in a panel replacement mode (the MDI child occupies the space where the Panel was) and the Main form caption is generated dynamically (as there are many modes that the program could run as)

On selecting an MDI child form (such as Item Maintenance) the main form title changes to a concatenated caption - the original main form caption followed by the MDI child form caption in square brackets. This is as expected.

On exit of the maintenance IN ALMOST ALL CASES the MDI child form although closed, still passes the form caption to the main form so although you have exited back to the main form the last entered MDI form caption is on the main form. This could be a feature but is not wanted.

Have tried resetting the main form caption after closing all MDI children, but even when this is done and DEBUGged the caption is the same after as before. It suggests that the main form caption is overridden, but with what?

Example 'home1click(Sender)' called on exit from any MDI child process.

procedure TForm1.Home1Click(Sender: TObject);
var i:integer;
  for i := MDIChildCount-1 downto 0 do   // close open windows, who ever they are...
  if loggedin=true then ButtonMenuOn;
  panel1.visible:=true;                          // MDI Panel
<< at this point caption might be 'Document Tracking System - [Item Maintenance] >>
  form1.Caption:=UpCaseFirst(runt)+' Tracking System';
<< At this point caption is still 'Document Tracking System - [Item Maintenance] >>

As mentioned, not all MDI child exits do the same. All the forms have the same variable parameters, but on exit of the Population enquiry' panel using the same method as all the others the MDI Child title correctly disappears.

Any answers?
Question by:mornao
    LVL 6

    Accepted Solution

    Hello sir,

      Before you close the childform you set back the caption of the mainform.

    ie, OnClose event of the form when you are freeing the child form set the caption of the main form.

    for eg
    Under MDI form (say form1) when opening the form set the caption as follows

    procedure TForm1.Button1Click(Sender: TObject);
      fORM2 := TForm2.Create(Self);
      Form1.Caption := UpCaseFirst(runt)+' Tracking System'

    Under child form (say form2) when closing set back the caption as follows

    procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
      Form1.Caption := 'Tracking System';
      Action := caFree;

    with regards,
    LVL 1

    Expert Comment

    first of all I do not preffer using MDI forms it has many problems, I preffer to use a normal forms and use an API function in the creation of each of your forms (except 4 the main) so it looks like:

    procedure TForm2.FormCreate(Sender: TObject);
      SetWindowPos(self.Handle, HWND_TOPMOST, 0, 0, 0, 0 , SWP_NOSIZE or SWP_NOMOVE);

    and feel free to act with your main and virtual children forms
    try this it will make form2 acts like a child of form1 with some better features, in other way tou build your MDI application manually
    but if you still wanna use MDi inform me to find another solution within MDI

    best regards
    LVL 1

    Author Comment

    The first response was accepted as there are multiple MDI children involved.

    It was given a GOOD rating because all that was required was for FromClose(Sender,caAction) to be populated with a caFree. The Form1.Caption is retained and does not need resetting each time you exit the MDI Child.  The only thing that caused some headache was to avoid the lethal embrace - cured by not calling the close in the MDI child but letting the Form1.Home1Click(Sender) look after everything! It calls the FormClose(Sender,caAction).

    The whole point of it being MDI was to give a consistant feel to the application, and allow trans-window messaging (such as turning off options when in the child but turning others on, and allowing the program still to event on them).

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
    In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now