Board index » delphi » OnChange headaches

OnChange headaches

I have just wasted two days with a problem caused by an OnChange
event. Not for the first time either.

What I want it to do is fire when the actual entry is changed by
the user - what _actually_ happens is that it fires behind the
scenes because it is linked to a table field so that when if
first gets 'filled' e.g. the form opens, OnChange fires, when it
closes OnChange fires.

Pat Bell

 

Re:OnChange headaches


Quote
"P.S.Bell" wrote:
> I have just wasted two days with a problem caused by an OnChange
> event. Not for the first time either.

> What I want it to do is fire when the actual entry is changed by
> the user - what _actually_ happens is that it fires behind the
> scenes because it is linked to a table field so that when if
> first gets 'filled' e.g. the form opens, OnChange fires, when it
> closes OnChange fires.

> Pat Bell

What kind of OnChange are you talking about?  I'll assume that is a
TField.OnChange.

If this is the case, maybe you can use an OnValidate handler and check
if the original value of the field has been changed to decide if fire or
not the process you want.  This is a temporary solution.  But we need to
know more about your problem to determine what's happening.

Victor H. Ulloa
Tierra Fertil S.A.

Re:OnChange headaches


On Thu, 11 Feb 1999 18:38:41 GMT, "P.S.Bell" <p...@PatBell.demon.co.uk>
wrote:

Quote
>I have just wasted two days with a problem caused by an OnChange
>event. Not for the first time either.

>What I want it to do is fire when the actual entry is changed by
>the user - what _actually_ happens is that it fires behind the
>scenes because it is linked to a table field so that when if
>first gets 'filled' e.g. the form opens, OnChange fires, when it
>closes OnChange fires.

>Pat Bell

You've not said what type of component is giving the trouble. However,
let me give an example assuming it's a TEdit. You can create an
OnChange handler for the component, but not connect it in the Object
Inspector. However, in the OnEnter event, you can connnect it:

        Edit1.OnChange := Edit1Change;

In the OnExit event, you can disconnect it:

        Edit1.OnChange := nil;

This is always safe to do. Thus, you would only be connected while the
edit control has focus.

Steve F (Team B)

Re:OnChange headaches


Thanks, it was in dbedits I was having this problem. I had been
planning to compare global variables setting OnEnter and
checking OnExit but your solution is more elegant.

Pat Bell

Re:OnChange headaches


Hi,

Maybe this can help you (I suppose we are talking about a dbedit)..

procedure DbEditChange(Sender: TObject);
begin
    if TEdit(Sender).Focused then
    begin
        // Your old code ...
    end;//if
end;

HTH

P.S.Bell escribi en mensaje ...

Quote
>I have just wasted two days with a problem caused by an OnChange
>event. Not for the first time either.

>What I want it to do is fire when the actual entry is changed by
>the user - what _actually_ happens is that it fires behind the
>scenes because it is linked to a table field so that when if
>first gets 'filled' e.g. the form opens, OnChange fires, when it
>closes OnChange fires.

>Pat Bell

Other Threads