Solved

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

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

685 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