Solved

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

Posted on 2001-07-11
8
280 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
  • 4
  • 3
8 Comments
 
LVL 1

Expert Comment

by:alx512
Comment Utility
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
Comment Utility
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 100 total points
Comment Utility
procedure TForm3.StringGrid1MouseDown(Sender: TObject;
 Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  if right button was pressed then
    Application.MainForm.Next;
end;
0
 
LVL 1

Expert Comment

by:alx512
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 1

Expert Comment

by:piscean
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Ok. No problem. I really try to give a common answer.
Good luck!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

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…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

14 Experts available now in Live!

Get 1:1 Help Now