Solved

How to determine MDI active form

Posted on 2004-08-08
8
2,380 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 303
build html 5 client that connect to indy Tidtcpserver 3 395
Reconfigure Delphi Install? 2 51
Create a path if not exists 7 77
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

770 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