?
Solved

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

Posted on 2014-09-04
4
Medium Priority
?
245 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 2000 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

765 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