Solved

Delphi 7: How to close a child form by double clicking on it

Posted on 2009-07-07
3
699 Views
Last Modified: 2013-11-23
Dear Experts,
I have a form that pops up to invite the user to select from a list of options.   The list is displayed as a grid inside a form.  I want the user to be able to double click one of the rows to select that item and automatically close the child form that displays the grid.  

I can work out how to generate the doubleclick event.  In the Delphi 7 IDE I can get it to generate the following code for the child form:

procedure TForm4.NextGrid1DblClick(Sender: TObject);
begin

end;

However I am not sure how to make the child form return control to the parent form.

If I just click an OK button on the child form I can grab the user's selection with this code:

   if (Form4.showmodal = mrOK) then
      result:= Form4.NextGrid1.SelectedRow
  else
     result:=-1;

How can I achieve a similar thing by double clicking.  

In Visual C++ I could send a windows message with WM_CLOSE but I'm not sure how suitable this is in Delphi.
Sincerely,

Philip Truscott
0
Comment
Question by:PTRUSCOTT
3 Comments
 
LVL 4

Accepted Solution

by:
JonasMalmsten earned 250 total points
ID: 24800696
In the double click event, put

ModalResult := mrOk;

control will be returned to the calling form (back to after ShowModal). You can close the form from here after you have extracted the information you need from the form (selected row of the grid).
0
 
LVL 1

Author Comment

by:PTRUSCOTT
ID: 24800910
Amazing.  It feels as if I received a correct answer in real time!  Thanks! It worked!
0
 
LVL 22

Expert Comment

by:8080_Diver
ID: 24804073
You might also want to make sure that you add the following line in the code that called the modal form so that you don't code in a memory leak.
Form4.Release;
P.s. I do hope that you are not actually using  the automatically generated names for the components you are putting on forms or for the forms themselves.  This is Not Good Codding Practice. ;-)
 
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

947 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

18 Experts available now in Live!

Get 1:1 Help Now