Solved

How to determine MDI active form

Posted on 2004-08-08
8
2,288 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

20 Experts available now in Live!

Get 1:1 Help Now