Solved

How to determine MDI active form

Posted on 2004-08-08
8
2,521 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
Industry Leaders: 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

732 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