Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Which button did I press?

Posted on 2002-07-15
5
Medium Priority
?
198 Views
Last Modified: 2010-04-04
I wanted to know if somebody with a little more than experience and knowledge that me,  can help me with the following thing:

In a form of entrance of data, there is a series of TEdits where numeric values are entered. In one of them, the value is not allowed to be 0 (zero), so in the event TEdit1.OnExit  I wrote a routine so that in case that the value is 0 it appears a MessageDlg with the error. But it happens that if I press the button to Cancel, AND I am in that TEdit, it evaluates the event OnExit and it doesn't cancel until it doesn't put a value <> 0.

Then, like this could solve? Is there a way to  indicate in TEdit1.OnExit that I pressed the button to so it doesn't evaluate the condition?

Thank you and greetings for all those that read this message

Juan Carlos
0
Comment
Question by:juank
[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
5 Comments
 
LVL 1

Accepted Solution

by:
DavidLeeding earned 300 total points
ID: 7155851
Hi

Try using the "Focused" function of your Cancel button as part of your OnExit code. Eg:

procedure TForm1.Edit1Exit(Sender: TObject);
begin

  // check whether the cancel button is focused
  if not Button1.Focused then  

    // it's not, so do validation stuff:
    if StrToIntDef(Edit1.Text, 0) = 0 then
    begin
      MessageDlg('Zero is not allowed', mtError, [mbOk], 0);
      Edit1.SetFocus
    end;

end;
0
 
LVL 2

Expert Comment

by:mikepj
ID: 7155915
Why not check the contents of the important TEdit when the button is pressed?  Just call OnEdit1Exit(self) when Cancel is pressed...

0
 
LVL 3

Expert Comment

by:marcoszorrilla
ID: 7156350
You can write a function for testing all the tedits than you want to control and set the KeyPreview of this form to True in order to test if the Esc key is pressed (in the even OnKeyPress from this form, an then call too this function.

Best Regards.
Marcos.
0
 
LVL 17

Expert Comment

by:geobul
ID: 7156555
Hi,
If I understand you correctly then try the following:

procedure TForm1.Edit1Exit(Sender: TObject);
begin
 try
  if StrToInt(Edit1.Text) = 0 then
   if MessageDlg('Zero is not allowed', mtError, [mbOk,mbCancel], 0) = mrOk then
     Edit1.SetFocus;
 except
   if MessageDlg(Numeric values only', mtError, [mbOk,mbCancel], 0) = mrOk then
     Edit1.SetFocus;
 end;
end;

Regards, Geo
0
 

Author Comment

by:juank
ID: 7158021
It's a good solution. Finally, with my mind a little clear I found a method using the Form1.ActiveControl. So if the ActiveControl is BtnCancel, no validation has to be done.
It works. Anyway thank you
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

688 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