Solved

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

Posted on 2014-09-04
4
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: 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

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
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

691 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