When Clause behavior of GET

Post Reply
Milan Mehta
Posts: 115
Joined: Mon Oct 17, 2005 4:42 am
Location: India

When Clause behavior of GET

Post by Milan Mehta »

Dear All,

I am facing a typical problem regarding When clause of GET. Whenever I am getting focus for a GET, When clause of all the GET of that Dialog gets executed. Is that normal behavior ? If so, how to avoid that ?

My problem is I am recalculating subsequent GETs based on the value of a GET. But I wish to program it such a way that user can override the default calculation done by When clause.

Following is a self containing sample.

TIA

Milan.

-------------------------------------------Cut----------------------------
#include "FiveWin.ch"

#define ETVAR1 101
#define ETVAR2 102
#define ETVAR3 103
#define ETVAR4 104
#define PBOK 105

function Main()

Local oDlg, oVar1, oVar2, oVar3, oVar4
LOCAL nVar1, nVar2, nVar3, nVar4

nVar1 := nVar2 := nVar3 := nVar4 := 0

DEFINE DIALOG oDlg TITLE "Test Update Dialog" RESOURCE "Test"

REDEFINE GET oVar1 VAR nVar1 ID ETVAR1 PICTURE "999999.99" OF oDlg;
VALID {|| nVar2 := nVar1 * 0.125/100, nVar3 := nVar1 * 0.010/100, nVar4 := nVar1 * 0.07/100, .T.}

REDEFINE GET oVar2 VAR nVar2 ID ETVAR2 PICTURE "999999.99" OF oDlg
// WHEN {|| nVar2 := nVar1 * 0.125/100, .T.}

REDEFINE GET oVar3 VAR nVar3 ID ETVAR3 PICTURE "999999.99" OF oDlg WHEN {|| MsgInfo ('When of Var3'), .T.} VALID {|| MsgInfo ('Valid of Var3'), .T.}

REDEFINE GET oVar4 VAR nVar4 ID ETVAR4 PICTURE "999999.99" OF oDlg WHEN {|| MsgInfo ('When of Var4'), .T.}

REDEFINE BUTTON ID PBOK ACTION oDlg:End()

ACTIVATE DIALOG oDlg

return nil
-------------------------------------------Paste--------------------------
RC file.
--------------------------------------------Cut---------------------------
#define ETVAR1 101
#define ETVAR2 102
#define ETVAR3 103
#define ETVAR4 104
#define PBOK 105

TEST DIALOG 6, 15, 260, 167
STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX
CAPTION "Dialog Update"
FONT 8, "MS Sans Serif"
{
EDITTEXT ETVAR1, 64, 20, 49, 18
EDITTEXT ETVAR2, 64, 43, 48, 18
EDITTEXT ETVAR3, 64, 68, 49, 18
EDITTEXT ETVAR4, 64, 97, 51, 18
PUSHBUTTON "Ok", PBOK, 78, 135, 50, 14
}
-------------------------------------------Paste--------------------------
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Milan,

Yes, its a typicall behavior. You can avoid it temporarly changing the bWhen DATA of the GETs:

oGet:bWhen := nil

and later on restoring them
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Milan,

I am not clear on what you are trying to accomplish. Your example doesn't match your description. The WHEN clause is usually used to ensure a condition, but you seem to be using it to make a calculation.

Perhaps you should be using bLostFocus. You could calculate the values of Gets 2-4 and place the results in the GETs when the user exits Get1. Then the user would still be free to change the values. Here is an example showing just updating oGet2. You would need to add similar code for oGet3 and oGet4

oGet1:bLostFocus := { || oGet2:varPut( oGet1:varGet() * 0.125/100 ), oGet2:refresh() }

Now when the user enters a value in oGet1 then exits oGet1, oGet2's value is automatically calculated and entered into oGet2, but the user can override it.

There is a complication with this behavior, if the user changes the value in oGet1 after overriding the value in oGet2, then oGet2's value will get recalculated. This may or may not be what you want. If you don't want this behavior, then I would use a flag var to have the calculation occur only on the first exit from oGet1. Something like this:

oGet1:bLostFocus := { || if( lFirst, (oGet2:varPut( oGet1:varGet() * 0.125/100 ), oGet2:refresh()), ) }

James
Post Reply