Solved

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

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi cmd execution 6 60
Delphi IDE crash without error message ... 7 89
Convert a string into a TDateTime 5 60
PHP preg_replace code convert to Delphi 14 55
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

786 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