Solved

How to determine MDI active form

Posted on 2004-08-08
8
2,332 Views
Last Modified: 2008-01-09
I have an MDI main form with a panel (left aligned) that contains various controls: i.e. TMemo, TCombobox, TTreeView and TButton.
The child forms have different combinations of TMemo, TStringGrid and/or TEdit controls (depending on the type of child form).

The application has a number of TActions set up, one of which is "actPaste" which has the hotkey Ctrl+V assigned to it.

Say the user clicks in a TMemo on the parent MID form and then presses Ctrl+V.
How can the code that implements the paste action determine whether to paste the clipboard text into the TMemo on the main MDI form or into the TMemo on the topmost child form?
There doesn't seem to be anyway to know which form has focus (out of the parent and the topmost child) and therfor there seems no way to know which control should receive the clipboard data.

Paul


0
Comment
Question by:zebada
8 Comments
 
LVL 7

Accepted Solution

by:
LRHGuy earned 500 total points
ID: 11749896
You can use the global Screen variable...

Screen.ActiveForm   <-- always the form with the focus
Screen.ActiveControl  <-- the control on the form with the focus...

0
 
LVL 1

Expert Comment

by:aruana
ID: 11749934
The active property of a form will tell you which one is in focus.

at the main form, run a loop:

for n:=0 to (MainForm.MDIChildCount-1)
begin
  If MainForm.MDIChildren[n].Active then
  begin
    // do your thing here
  end;
end;

or you can use a while loop or what ever is suitable to your code.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 11750232
look at the activeMDIChild-property of your mdiForm (mainForm)

meikl ;-)
0
 
LVL 6

Author Comment

by:zebada
ID: 11750346
LRHGuy: I did a quick test of your suggestion - it appears to work and do what I need. I need to test it some more tonight...

aruana: The problem is not which child form is active, but which form out of the parent and the "active" child is active.

Kretzschmar: I did try that but the activeMDIchild always returns the topmost child (as expected) even when a control in the main/parent form has focus.

Paul
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Expert Comment

by:Ivanov_G
ID: 11750516
var
  frm    : TForm;
begin
  frm := Self.ActiveMDIChild
  // do whatever you want with FRM
0
 
LVL 6

Author Comment

by:zebada
ID: 11750614
Ivanov: The problem is not "how to get the active child form".
The problem is: how do I tell which form the active control is on, the "active child form" or the "parent MDI form"?

Check out the suggestion by LRHGuy, it appears to work well - I'm just doing some final testing...

Paul

0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 11750672
if you have the active control, you can always check who is its Owner and Parent...

procedure TForm1.Button1Click(Sender: TObject);
var
  str    : String;
begin
  str := Screen.ActiveControl.Owner.ClassName;
  ShowMessage(str);
end;
0
 
LVL 6

Author Comment

by:zebada
ID: 11750703
Yes that is correct, that is what PRHGuy already said.
Thanks
Paul
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
oracle global variables 4 63
How to convert memory stream to PDF file 6 20
How to build JSON File in Delphi 6 3 14
DBGrid or StringGrid ? 6 71
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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