Solved

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

Posted on 2009-07-07
3
695 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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