Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Duplicate MDI Form



Permlink Replies: 4 - Last Post: Dec 18, 2017 10:45 AM Last Post By: Remy Lebeau (Te... Threads: [ Previous | Next ]
George Kuascha

Posts: 20
Registered: 3/4/01
Duplicate MDI Form
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 14, 2017 8:28 AM
I am opening the same MDI Form multiple times on the Main Form. The different MDI Forms display different data aligned vertically on the Main Form. I have toolbuttons on the Main Form that perform actions on the MDI Forms. The toolbuttons will only perform actions on the last MDI Form that was opened. How do I identify and change the active MDI Form such that the toolbuttons will work properly on the active form?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Duplicate MDI Form
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 14, 2017 10:49 AM   in response to: George Kuascha in response to: George Kuascha
George Kuascha wrote:

I have toolbuttons on the Main Form that perform actions on the MDI
Forms. The toolbuttons will only perform actions on the last MDI Form
that was opened. How do I identify and change the active MDI Form such
that the toolbuttons will work properly on the active form?

TForm has an ActiveMDIChild property.

--
Remy Lebeau (TeamB)
George Kuascha

Posts: 20
Registered: 3/4/01
Re: Duplicate MDI Form
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 16, 2017 1:08 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
George Kuascha wrote:

I have toolbuttons on the Main Form that perform actions on the MDI
Forms. The toolbuttons will only perform actions on the last MDI Form
that was opened. How do I identify and change the active MDI Form such
that the toolbuttons will work properly on the active form?

TForm has an ActiveMDIChild property.

--
Remy Lebeau (TeamB)

I not sure how to use ActiveMDIChild property to change focus from one MDIform to another. The following code does not work.
How would I distinguish between the different open MDIforms since they are using the same form design?

procedure TFormChart.FormClick(Sender: TObject);
begin
SDIFormMain.SetFocus;
SDIFormMain.ActiveMDIChild.Enabled:= true;
end;
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: Duplicate MDI Form
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 17, 2017 12:16 AM   in response to: George Kuascha in response to: George Kuascha
George Kuascha wrote:

Remy Lebeau (TeamB) wrote:
George Kuascha wrote:

I have toolbuttons on the Main Form that perform actions on the
MDI Forms. The toolbuttons will only perform actions on the last
MDI Form that was opened. How do I identify and change the active
MDI Form such that the toolbuttons will work properly on the
active form?

TForm has an ActiveMDIChild property.

--
Remy Lebeau (TeamB)

I not sure how to use ActiveMDIChild property to change focus from
one MDIform to another.

That makes no sense since the activemdichild is the form with focus
in your scenarion.

If you create several instances of the same form class you can no
longer rely on the form variable the IDE creates for you, since that
variable only holds the reference to the last form created. To find the
other instances you have to itertate over the main form's MDIChildren
array..

for i:= 0 to mdichildcount-1 do
if mdichildren[i].Classtype = TMyMultipleInstanceMDIChild then
... found one

The problem remains how to identify the instance to activate or operate
on. There is nothing in the VCL that would help you here. The MDI child
in question could, for example, store its Self reference into a
variable in the OnActivate event to track which of the forms was last
accessed by the user.


--
Peter Below
TeamB

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Duplicate MDI Form
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 18, 2017 10:45 AM   in response to: George Kuascha in response to: George Kuascha
George Kuascha wrote:

I not sure how to use ActiveMDIChild property to change focus from
one MDIform to another.

You can't, as it is a read-only property. It simply tells you which
child is currently active.

If you want to change which child is active, simply call BringToFront()
on the desired child.

The following code does not work.

You have to bring the desired child to the foreground before you can
then set focus on it.

How would I distinguish between the different open MDIforms since they
are using the same form design?

Each child Form is a different object in memory. Simply compare the
object pointers. Or give each child a unique Name, or Caption, or
whatever.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02