Page 1 of 1

onchange event on a control

Posted: Thu Sep 23, 2010 12:23 pm
by l3whmg
Hello everyone,
I found a malfunction during the use of the "OnChange" event in a control. I am referring to the HMG 3.0.35. I've attached an example that generates the error and this is the error.
image
image
ScreenShot001.jpg (65.46 KiB) Viewed 4919 times
Also, are indicative only for those who are developing HMG 4, I found that the use of "ONMOUSECLICK Nil" (when defining a form) crash the program.

Best regards.

Re: onchange event on a control

Posted: Thu Sep 23, 2010 12:52 pm
by esgici
Ciao Luigi

Please try this :

Code: Select all

/***********************************************************
* calculate
***********************************************************/
STATIC FUNCTION Win1_Calculate()

IF IsControlDefined( Win1Frm, nfield01 )

   Win1Frm.nfield03.Value := Win1Frm.nfield01.Value  + Win1Frm.nfield02.Value
   
ENDIF

RETURN NIL
And please don't ask me "why?",

because I don't know; simply tried and succeed (error gone away) :(

Regards

--

Esgici

Re: onchange event on a control

Posted: Thu Sep 23, 2010 1:08 pm
by l3whmg
Hi Esgici,
many thanks for your quickly replay :) ...but I know :oops: this solution (I've used a similar solution in my app).
I think, but I'm not sure, can be the events order activation after (and not before :?: ) form definition.

Best regards

Re: onchange event on a control

Posted: Thu Sep 23, 2010 1:27 pm
by esgici
I'm not sure, but I'm thinking that way :

ACTIVATE command always triggered all ON CHANGE procs/blocks BEFORE (?) activation :(

Ciao :)

--

Esgici

Re: onchange event on a control

Posted: Thu Sep 23, 2010 1:27 pm
by Rathinagiri
Hi Luigi,

It is possible to fire the change event even before activation of window. Actually it is what happening here.

You have hooked the on change event of nfield01. When the value is changed, it refers to nfield02, and nfield03 which were not at all defined at that time! That is why the error is occuring.

Actually Setting an INPUTMASK to a textbox changes its value to 0.

So, it is safe to check whether the other controls (or the last control) are defined.

Re: onchange event on a control

Posted: Thu Sep 23, 2010 1:51 pm
by l3whmg
Hello to everyone and thanks for your interest.

I think, given the response of Rathi, are confirmed my doubts about the activation sequence of events.
Obviously, the solution is that you proposed, but I think (let me :oops: ) that it is "wrong".
I think the cycle should respect the sequence: definition of the form, the form events, events for controls (in the order in which they were defined on the form). Only if the form has been completely defined I can trigger an event like onchange.
But this is My Humble Opinion :)

Anyway thanks for your answers :D .