Solved

Which button did I press?

Posted on 2002-07-15
5
185 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 100 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

Industry Leaders: 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
Create Database on Android via Delphi dbExpress 3 143
Delphi 2 91
FMX TEdit KeyUp handler detecting  "enter" key 4 63
Posting a string with PostMessage 23 49
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

751 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