Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-07-07
3
Medium Priority
?
738 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 1000 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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…
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

824 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