Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do you shift focus from one mdi child to another?

Posted on 2001-07-11
8
Medium Priority
?
288 Views
Last Modified: 2010-04-06
How do you shift focus from one mdi child to another?

* given:
  2 mdi child forms with an alClient stringgrid and a pop-  up menu each (properties: keypreview=true)
  > mdichild1 and mdichild2

* problem:
  while focus in on mdichild1 ... a "right click event"   of the stringgrid in mdichild2 does not shift the focus from mdichild1 to mdichild2.

* what i want to happen:
  "right click event" of mdichild2 shifts the focus from mdichild1 to mdichild2 so that activemdichild=mdichild2

thanks :)
 
0
Comment
Question by:ttanyag
[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
  • 4
  • 3
8 Comments
 
LVL 1

Expert Comment

by:alx512
ID: 6275768
In OnMouseDown event handler write this code:

procedure TForm2.StringGrid1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Show;
  StringGrid1.SetFocus;
end;
0
 
LVL 9

Expert Comment

by:ITugay
ID: 6276318
Hi ttanyag,

.......
implemenatation
uses
   Unit2;
........

procedure TForm3.StringGrid1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbRight then
    Form2.Show; // Form2 is another MDIChild form.
end;

-----
Igor.
0
 
LVL 1

Accepted Solution

by:
piscean earned 300 total points
ID: 6279218
procedure TForm3.StringGrid1MouseDown(Sender: TObject;
 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if right button was pressed then
    Application.MainForm.Next;
end;
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Expert Comment

by:alx512
ID: 6279702
You accept a wrong answer, this code work only if you have two Child windows, and what will be if there are three windows?
0
 
LVL 1

Expert Comment

by:piscean
ID: 6279742
I just want to make it clear to you that repeatedly calling the Next method of a MDIParent will switch through all the child forms (no matter how many children are there).  Haven't you passed through this info in the Help file (at least...)  I wonder what happened in your code why the thing you were saying happened!  I can explain these things to you if you want info (huh!)
0
 
LVL 1

Expert Comment

by:alx512
ID: 6279759
Look:

  Form1 - MDI
  Form2 - Child
  Form3 - Child and Focused
  Form4 - Child

You click in Form2 - then Form2 must be Focused,
but your code activate the Form4.
 
0
 
LVL 1

Expert Comment

by:piscean
ID: 6284930
My answer was based on the situation given by "ttanyag".  And that definitely filled his needs so you don't have to be rude saying what I provided was incorrect ('coz it's not!).  The only missing stuff there is the checking whether mdichild2 is in focus or not.  It should be this way rather...

procedure OnMouseDownEvent;
begin
  if right_click and (application.mainform.activemdichild.handle <> handle) then
  application.mainform.next;
end;

Although what you've posted before (Form.Show) was correct, there's a rule here of avoiding duplications so I posted a different one which in turn produces the same result.  The only difference is that I've posted it as an answer and you made yours a comment so it was me that was rated.  We're in the Delphi world man ... one problem has lots of solutions. And that makes us above the others!

About your discussion on having 3 (or more) children.  You're right in saying that the answer I've provided was wrong.  But that can only be WRONG if the problem states that it really will have 3 or more forms!  BUT it was clearly stated that IT HAS ONLY TWO! I should have posted a different answer if the problem said it will have >3 children.  So I guess that cleared your discussion.

And BTW, about this ...
"Look:
Form1 - MDI
Form2 - Child ...".  This will only work on right clicks (not just clicks).  Try left click and everything goes strange ...

0
 
LVL 1

Expert Comment

by:alx512
ID: 6285018
Ok. No problem. I really try to give a common answer.
Good luck!
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

715 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