Delphi RSS Resources, Delphi Components, Delphi Sites, Articles, Dynamic XML Feeds, Tutorials, Sources
 
 
 
Google
 
Web delphirss.com
| Server-Scripts.com | Informations for JAVA | Informations for PHP | SEO Web Links | Borland Delphi
 

MDI

MDI Windows
Sizing MDI child windows
Calling functions from different MDIChilds
Trapping a MDI Child Event
Closing MDI childs
Selecting MDI children with TabSet
How many Child Windows are open
Open MDI Form at specific size
MDI Problem with hints
Removing title bar from MDI child form


MDI Windows

Question

I want to set a minimum tracking size for a MDI form in my application.

Answer

A:
Put the following line in the private part of your form class...

 procedure WMGetMinMaxInfo(var Message : TWMGetMinMaxInfo); message
WM_GETMINMAXINFO;

... and the next function in the implementation section of the unit...

procedure YourClassNameHere.WMGetMinMaxInfo(var Message : TWMGetMinMaxInfo);
begin
{
The following code prevents the user from changing the size of the form but
replace Width and Height
with the min and max values that you require. (anyway you get the idea).
}
    Message.MinMaxInfo^.ptMinTrackSize := Point(Width, Height);
    Message.MinMaxInfo^.ptMaxTrackSize := Point(Width, Height);
end;


Sizing MDI child windows

Question

We are using MDI for what is really a single document application. In this
application we simply present the user with different views of the data.
My question is once I create my MDI child windows, I would like to have them be
a certain default size. I can achieve this by sending a form resize message and
trapping that in each window and forcing it to the desired size.
Is this the best way to achieve this?

Answer

A:
If you want to set the size at design time, then just set the Position property
of the MDI form to poDefaultPosOnly, and it will always be created with the size
you used at design time.  If you want to let the user set the default, my
suggestion would be to add an option to the system menu (I use a component
called acMenus for this) to let the user save the current size to an INI file
setting (or two, I use one variable that is comma-delimited).  Then in the
FormCreate method, I read the INI file and set Height and Width appropriately.
No need for sending messages after the form is created.

Calling functions from different MDIChilds

Question

I'm working on a MDI-project. All MDIChilds have two functions called
'DefaultSize' and 'MinimalSize'. I would like to call this functions
from the MDIParent-form like this:

ActiveMDIChild.DefaultSize;

This isn't working. When the function is called directly, e.g.:

MyMDIChild1.DefaultSize;

it works. So here's my question:

Is it possible to access functions of the active MDIChild without
knowing it's name?

Answer

A:
Try this:

var
  MyMDIForm: TForm;

begin
 
  MyMDIForm:=ActiveMDIChild;
  MyMDIForm.DefaultSize;

end;

I have not tried it myself, but I'll hold my thumbs... :-)

A:
Try casting the reference to ActiveMDIChild:

TChild(ActiveMDIChild).SomeMethod;

Trapping a MDI Child Event

Question

I have written a procedure to enable/disable menu and toolbar buttons and
it works fine calling it from the MCIFrame window menus. How can I trap
when the user closes a MDIChild Window using the MDIChild System Menu |
Close.
Example:
This works -> Select the application's file menu and choose close window.
If it is the last window then the appropriate menu items are greyed out.
This does not work -> User clicks on the system menu of the child window
and chooses close. Here is the problem, there is no way to tell if this
was the last window closed.

Answer

A:
procedure TMainForm.FormCreate(Sender: TObject);
begin
  {  place FormCreate code here  }
  Screen.OnActiveFormChange := UpdateObjectss;
  {  and here, too, if you like  }
end;

procedure TMainForm.UpdateObjects(Sender: TObject);
begin
  .Enabled := MDIChildCount > 0;
end;

The (MDIChildCount > 0) part returns true if _any_ child windows are
open, and false otherwise.  So, you don't have to worry about
counting the chidren that are open.

Closing MDI childs

Question

What must make so that a child form of a MDI application could be destroyed to
if same?
Upon executing the code associated with a button of the child form (this
action only it can be carried when is pressed this button!) I need that is
destroyed to if same and that create the following child form. I have
>treated of several things, but up until now what is only that it does not
provoke an errorGPF is when I establish the focus to a control of the main
form (MDIPARENT) and the user presses a key or accomplishes other action that
could be detected and in which put the code that accomplishes the destruction.

Answer

A:
To destroy a MDI Child, you should take it off the autocreate forms
(Project options), create it at runtime and, on the OnClose event of the
child, assign caFree to the Action Variable, like this
    Action := caFree;

Selecting MDI children with TabSet

Question

I have a TabSet on a MDI application, and I want to have the
ability to select any of the open MDI children using this tabset.

Answer

A:
It seems that MDI children don't respond to the
same Windows messages that other windows do. This is what
I had to do in order to select a specific MDI child
and make it active. Here I'm reading from an TINIFile
component and activating the specific MDI child:

{
Set active MDI child window. We have to post a message
to the Windows API because MDI child windows respond
to an abnormal set of window messages.
}
;	i := ReadInteger( 'Main', 'ActiveMDIChild', -1 )
;	IF (i>=0) AND (i).  Mdi children
are part of an array called (oddly enough) MDIChildren.  You can do
something like this for instance.....

For i := 0 To Form1.MDIChildCount - 1 Do
begin
        If Form1.MDIChildren[i].Caption = 'This One!' Then
                {Activate the child form or perform operation here}
end;

The MDIChildren[x] is a pointer to an instance of an MDI child.  Using IS
and AS will allow you to use the methods and properties of any variety of
child forms.

A:
1. When a file is opened a new Tab is added to the Tabset, and its
"caption" is set to the filename of that file . I then add the form as
an object to the tabset using the Tabset.AddObject command.

2. When I click on a tabset, I use the following to access the
correct file:
  TForm(TabsSet.Items.Objects[TabSet.TabIndex]).Show;

How many Child Windows are open

Question

In my MDI application, I would like to trigger an event - mainly showing
some special status panel when ZERO child windows exist. Conversely, I would
like to hide this status panel when AT LEAST ONE Child Window exists.

Answer

A:
Example (from online help):

  with Form1 do
    for I := 0 to MDIChildCount-1 do
      MDIChildren[I].Close;

So,
 if (MDIChildCount=0) then ShowTheStatusPanel
   else HideTheStatusPanel;

A:
Create a general proc called OnChildCountChange in you main form
put something like this in there

if MDIChildCount = 0 then
  Panel1.Show else Panel1.Hide;

in the Destroy and Create of your child form call that proc -

MainForm.OnChildCountChange;

to update the status of the status bar

Open MDI Form at specific size

Question

Open MDI Form at specific size?

Answer

A:
var
  ProjectWindow: TWndProject;
begin
  If ProjectActive=false then begin
    LockWindowUpdate(ClientHandle);
    ProjectWindow:=TWndProject.Create(self);
    ProjectWindow.Left:=10;
    ProjectWindow.Top:=10;
    ProjectWindow.Width:=373;
    ProjecTwindow.Height:=222;
    ProjectWindow.Show;
    LockWindowUpdate(0);
  end;
end;

Use LockWindowUpdate before creation and after creation is finished.

MDI Problem with hints

Question

I've a MDI application with on the main form a status bar.
How could I display messages on the main status bar when I'm running code at
one of the child forms.
Main.Status := 'Hint'; This wouldn't work because the Main variable isn't
know at the child form. And if I add main to the uses line I get Circulair
unit reference....

Answer

If You simply want to display the hints from controls on a child form do
this to your main form.

1) declare this procedure in your main form class.

  private
    {============================================================}
    { Procedure called by application each time the application  }
    { would like to display a hint.  Adds the hint to the status }
    { panel.                                                     }
    {============================================================}
    procedure
      ShowHint
      (
        Sender : TObject
      );


then in the mainform .creat procedure add this line.

  Application.OnHint := ShowHint;{ Display the hint in the status}

now here is the ShowHint Function from the main form.

{================================================================}
{ Update the pnlStatusText.Caption with the hint for the control }
{ that the mose is over.                                         }
{================================================================}
procedure
TMainFrame.ShowHint
(
  Sender : TObject  {Object calling this procedure}
);
begin
  pnlStatusText.Caption := Application.Hint;
end; { TMainFrame.ShowHint }


that should do it.  You will only need to set the hints for the controls
in all windows including the controls on the main frame window.  Set the
show hint property to false or the hints will also display in the normal
pop-up fashion along with the status bar display.

Removing title bar from MDI child form

Question

How to remove title bars from MDI child forms?

Answer

{
  We were able to kill the title bar of an MDI child by doing the following:
}
type
  TForm2 = class(TForm)
	{ other stuff above }
	procedure CreateParams(var Params: TCreateParams); override;
	{ other stuff below }
  end;


procedure TForm2.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  Params.Style := Params.Style and not WS_OVERLAPPEDWINDOW or WS_BORDER
end;










© DelphiRSS.com. All Rights Reserved.