Solved

How to determine MDI active form

Posted on 2004-08-08
8
2,604 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month11 days, 15 hours left to enroll

623 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