Solved

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

Posted on 2014-09-04
4
234 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
zeroFront challenge 7 80
bunnyEars2 challenge 6 108
countX 22 85
split53 challenge 7 80
Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now