Solved

In Delphi VCL, how can you exit without completing all actions?

Posted on 2014-09-04
4
237 Views
Last Modified: 2014-09-05
I have exit procedures on lots of visual controls, but when the user hits buttons with the function cancel or exit I want to stop processing on all these exit processes.

Since the program does not get to the Cancel or Exit buttons until it has it completed the exit processes, it takes two clicks to exit the form.

Is the unavoidable, or is there a way this natural processing can be circumvented?

Here is a piece of code I have written to demonstrate the problem:

procedure TForm1.Button1Exit(Sender: TObject);
begin
  MessageDlg('I am here', mtInformation, [mbOK], 0);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  close;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
  ActiveControl := Button1;
end;

Open in new window


In this program, it starts with the focus on Button1, so when I click Button2, I still get the message from Button1. This is the type of action I want to avoid.
0
Comment
Question by:GrahamDLovell
  • 2
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
MerijnB earned 500 total points
ID: 40305334
Sort of a guess, will this work?

procedure TForm1.Button1Exit(Sender: TObject);
begin
  if ActiveControl <> Button2 then
    MessageDlg('I am here', mtInformation, [mbOK], 0);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  close;
end;

procedure TForm1.FormActivate(Sender: TObject);
begin
  ActiveControl := Button1;
end;
                                

Open in new window

0
 

Author Closing Comment

by:GrahamDLovell
ID: 40305387
Too logical!

I suppose I should have thought of it. I will have to put it on every field exit routine, but it will improve the functionality quite a bit.

Thanks.
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 40305391
It's not a 'golden' method I guess, still thinking of something better.
What kind of functionality do you have in the OnExit() of buttons?
0
 

Author Comment

by:GrahamDLovell
ID: 40305408
Depending on the value entered into the field, other fields are made visible or invisible, descriptions are changed, etc.

Your method will be workable, and not too hard to implement.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
why to use string 10 62
map interface methods 3 78
base64 decode encode 12 161
Android development question 2 75
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article will show, step by step, how to integrate R code into a R Sweave document
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…

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