Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.* 1 > Newsgroup comp.lang.clipper.visual-objects

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 05-30-2011, 09:00 AM
Krystian
Guest
 
Posts: n/a
Default Field validation

Hi,

I would like to "implement" standard clipper Valid statement for a
SingleLineEdit in a DataWindow
This is a piece of code from PostInit

oSFS := StringFS{HyperLabel{#nr_pesel}}
oHLVal := HyperLabel{#nr_pesel, , 'Błędny numer PESEL'}

oSFS:setValidation({|x| spr_pese(x)}, oHLVal)

SELFDCNr_pesel:FieldSpec := oSFS

function spr_pesel returns logic value.

What is wrong in it, what I miss to set, because the control does not
enter to function spr_pesel()

Any help is welcome, thanks a lot
But please "IN CAPITAL LETTERS" - I am on the beginning of my
adventure with CAVO
Krystian
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 05-30-2011, 12:08 PM
wolverine
Guest
 
Posts: n/a
Default Re: Field validation

If i'm not wrong the function in a codeblock cannot be strong typed.
Can be that the problem?

Sebastián

On 30 mayo, 06:00, Krystian <so...@softb.pl> wrote:
> Hi,
>
> I would like to "implement" standard clipper Valid statement for a
> SingleLineEdit in a DataWindow
> This is a piece of code from PostInit
>
> Â* Â* Â* Â* oSFS := StringFS{HyperLabel{#nr_pesel}}
> Â* Â* Â* Â* oHLVal := HyperLabel{#nr_pesel, , 'Błędny numer PESEL'}
>
> Â* Â* Â* Â* oSFS:setValidation({|x| spr_pese(x)}, oHLVal)
>
> Â* Â* Â* Â* SELFDCNr_pesel:FieldSpec := oSFS
>
> function spr_pesel returns logic value.
>
> What is wrong in it, what I miss to set, because the control does not
> enter to function spr_pesel()
>
> Any help is welcome, thanks a lot
> But please "IN CAPITAL LETTERS" - I am on the beginning of my
> adventure with CAVO
> Krystian


Reply With Quote
  #3 (permalink)  
Old 05-30-2011, 02:37 PM
Willie Moore
Guest
 
Posts: n/a
Default Re: Field validation

Krystian,

What version of VO are you using? Various parts of the GUI classes have
changed with the different releases so it is very difficult to give an
answer without knowing the version.

Regards,
Willie

"Krystian" wrote in message
news:4aeaf2f0-fa83-4d6e-b3ee-f6fc76cf0443@a26g2000vbo.googlegroups.com...

Hi,

I would like to "implement" standard clipper Valid statement for a
SingleLineEdit in a DataWindow
This is a piece of code from PostInit

oSFS := StringFS{HyperLabel{#nr_pesel}}
oHLVal := HyperLabel{#nr_pesel, , 'Błędny numer PESEL'}

oSFS:setValidation({|x| spr_pese(x)}, oHLVal)

SELFDCNr_pesel:FieldSpec := oSFS

function spr_pesel returns logic value.

What is wrong in it, what I miss to set, because the control does not
enter to function spr_pesel()

Any help is welcome, thanks a lot
But please "IN CAPITAL LETTERS" - I am on the beginning of my
adventure with CAVO
Krystian

Reply With Quote
  #4 (permalink)  
Old 05-30-2011, 04:20 PM
Roger Lawton
Guest
 
Posts: n/a
Default Re: Field validation

Krystian:

I use the setValidation method in my code and it works fine (VO28 sp2).
One thing to check is if your spr_pese(e) function is called anywhere else.
If not then it may not be loaded by the linker. I have had a few instances
where functions that are only executed from code blocks must be "phantom"
called so the linker will link them into the exe/dll.

Just a thought.

Roger


"Krystian" <softb@softb.pl> wrote in message
news:4aeaf2f0-fa83-4d6e-b3ee-f6fc76cf0443@a26g2000vbo.googlegroups.com...
Hi,

I would like to "implement" standard clipper Valid statement for a
SingleLineEdit in a DataWindow
This is a piece of code from PostInit

oSFS := StringFS{HyperLabel{#nr_pesel}}
oHLVal := HyperLabel{#nr_pesel, , 'Błędny numer PESEL'}

oSFS:setValidation({|x| spr_pese(x)}, oHLVal)

SELFDCNr_pesel:FieldSpec := oSFS

function spr_pesel returns logic value.

What is wrong in it, what I miss to set, because the control does not
enter to function spr_pesel()

Any help is welcome, thanks a lot
But please "IN CAPITAL LETTERS" - I am on the beginning of my
adventure with CAVO
Krystian

Reply With Quote
  #5 (permalink)  
Old 05-31-2011, 08:05 AM
richard.townsendrose
Guest
 
Posts: n/a
Default Re: Field validation

Krystian

below is the system which we use.

OBJECTS - VO is NOT clipper it is VO .... persevere - it will become
very easy ...

What we have used for many years is a validation system based on code
written in VO 1 days

So to start ...
Window. When the focus of the control being edited is lost - viz focus
goes somewhere else then the window:editfocuschange() method is called
by vo.

so subclass your window class and add:
CLASS V4_DataWindow INHERIT V4_ExtDataWindow

PROTECT lDirty AS LOGIC
PROTECT aTrigRefText AS ARRAY // array of controls that
trigger RefreshText in Editfocuschange
PROTECT aTrigDirty AS ARRAY // array of control that trigger
dirty state in editchange
PROTECT AllTrigDirty AS LOGIC // if true allcontrols trigges
dirty state
// PROTECT lDoNotify AS LOGIC

EXPORT ActivateEditChange AS LOGIC // Activete the dirty handling
EXPORT lValidationOn AS LOGIC // to validate from
EditFocusChange Method instead Notify

//PROTECT sUserAction AS SYMBOL //#ADD #EDIT #SIMILAR
INSTANCE sUserAction AS SYMBOL //#ADD #EDIT #SIMILAR // rgtr 150802

PROTECT aSYMBOLVars AS ARRAY //TabVarGet TabVarPut
PROTECT aFormatVars AS ARRAY
PROTECT aValueVars AS ARRAY

PROTECT oDocument AS Document // ARG121999
PROTECT cViewer AS STRING
PROTECT aViewers AS ARRAY // ARG121999
PROTECT oViewButton AS PushButton

//PROTECT oMaster AS Document // rgtr 140507
//PROTECT oViewMaster AS PushButton // rgtr 291106

DECLARE METHOD TABVarGet

you can see we have handling for "Save" and "Cancel" using the dirty
concept. and which fields can set it.
we have document viewing
we have a "TabVar" concept for variables common to several pages on a
tab

and using field spec we have a validation system. this starts it.
we have two things: validation and a call to "RefreshText()" method.
so this can set the phone no of a person when they are selected etc
etc.

METHOD EditFocusChange(oEditFocusChangeEvent) CLASS V4_DataWindow
LOCAL oControl AS Control
LOCAL lGotFocus AS LOGIC

oControl := IIF(oEditFocusChangeEvent == NULL_OBJECT, NULL_OBJECT,
oEditFocusChangeEvent:Control)
lGotFocus := IIF(oEditFocusChangeEvent == NULL_OBJECT, FALSE,
oEditFocusChangeEvent:GotFocus)
//Put your changes here

IF !lGotFocus .AND.
AScan(SELF:aTrigRefText,oControl:NameSym)>0 .AND.
oControl:ValueChanged
SELF:RefreshText(oControl:NameSym)
ENDIF

SUPER:EditFocusChange(oEditFocusChangeEvent)

IF !lGotFocus .AND. SELF:lValidationOn //if lValidation
is TRUE DO Validation
SELF:ControlValidation(oControl)
ENDIF

RETURN NIL

so here are the methods of the window needed:
METHOD CleanDirtyControls() CLASS V4_ExtDataWindow
LOCAL wLen AS DWORD // rgtr 080105 was word
LOCAL wX AS WORD
LOCAL oControl AS OBJECT

wLen := ALen(SELF:Controls)

FOR wX := 1 TO wLen
oControl:=SELF:Controls[wX]
IF oControl:FieldSpec <> NULL_OBJECT .AND.
IsMethod(oControl:FieldSpec,#Valid)
oControl:Background := oBrushNormal
ENDIF
NEXT

RETURN SELF
ACCESS Controls CLASS V4_ExtDataWindow
RETURN SELF:aControls
METHOD ControlValidation(oControl) CLASS V4_ExtDataWindow

IF oControl:FieldSpec <> NULL_OBJECT .AND.
IsMethod(oControl:FieldSpec,#Valid)
SELF:cWarningText := ''
IF !SELF:IsControlValid(oControl)
oControl:Background := oBrushYellow
SELF:AlertMessage('Error: '+SELF:cErrorText,MESSAGECONTROL)
ELSE
oControl:Background := oBrushNormal
IF !Empty(SELF:cWarningText)
SELF:AlertMessage('Warning: '+SELF:cWarningText,MESSAGECONTROL)
SELF:cWarningText := ''
ENDIF
ENDIF
ENDIF

RETURN TRUE
METHOD IsControlValid(oControl) CLASS V4_ExtDataWindow
LOCAL lOk := TRUE AS LOGIC

IF !IsAccess(oControl,#IsEnabled) .OR. oControl:IsEnabled
SELF:cErrorText := ''
IF oControl:FieldSpec <> NULL_OBJECT .AND.
IsMethod(oControl:FieldSpec,#Valid)
lOk := oControl:FieldSpec:Valid(oControl)
IF lOk
IF oControl:FieldSpec:Validation <> NIL
lOk := Eval(oControl:FieldSpec:Validation,oControl:Value)
IF !lOk
SELF:cErrorText := oControl:FieldSpec:Status
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF

RETURN lOk
METHOD IsRecordValid() CLASS V4_ExtDataWindow
LOCAL wLen AS DWORD // rgtr 080105 was word
LOCAL wX AS DWORD
LOCAL lOk AS LOGIC
LOCAL oControl AS OBJECT
LOCAL nFirstControlDirty AS DWORD

lOk := TRUE
nFirstControlDirty:=0
SELF:cErrorText := ''
wLen := ALen(SELF:Controls)

FOR wX := 1 TO wLen
oControl := SELF:Controls[wX]
IF oControl:FieldSpec <> NULL_OBJECT .AND.
IsMethod(oControl:FieldSpec,#Valid)
IF !SELF:IsControlValid(oControl)
IF IsControlEnabled(oControl) //CAL 070602 to keep disabled
controls gray
oControl:Background := oBrushYellow
ENDIF
lOk := FALSE

IF nFirstControlDirty=0
SELF:AlertMessage('Error: '+SELF:cErrorText,MESSAGECONTROL)
nFirstControlDirty:=wX
ENDIF

ELSE
IF IsControlEnabled(oControl) //CAL 070602 to keep disabled
controls gray
oControl:Background := oBrushNormal
ENDIF
ENDIF
ENDIF
NEXT

IF nFirstControlDirty>0
SELF:Controls[nFirstControlDirty]:SetFocus()
ENDIF

RETURN lOk

and here is the field spec stuff

CLASS MyFIELDSPEC INHERIT FieldSpec

PROTECT aValidations AS ARRAY
PROTECT auArgument AS ARRAY
PROTECT lForceUpper AS LOGIC
METHOD Init(oHyperLabel,uType,nLength,nDecimals) CLASS MyFIELDSPEC

SUPER:Init(oHyperLabel,uType,nLength,nDecimals)

aValidations:={}
auArgument:={}

RETURN SELF // rgtr 131003
CLASS F256Char INHERIT MyFIELDSPEC
METHOD Init() CLASS F256Char

SUPER:Init(HyperLabel{"F256Char","","",""},"C",256 ,0)

RETURN SELF // rgtr 190507

and here is some window initialisation stuff from a postinit.

METHOD PostInit(oWindow,iCtlID,oServer,uExtra) CLASS NamesEdit

SELF:Use(SELF:Owner:asNM)
SELF:UserAction:=#EDIT


SELFDCTyp1:fillUsing(SysObject():GetCat(NAME_POS ITION):ListBoxArray)
SELFDCTyp2:fillUsing(SysObject():GetCat(NAME_TYP E):ListBoxArray)

SELFDCInUseisable()
SELFCCGetRef:Hide()

// Set Validation (UserAction ASSIGN has new validation rules)
SELFDCNameX:FieldSpec:AppendValidation({|oCtrl|
CheckTitleOk(oCtrl)})
SELFDCContact:FieldSpec:AppendValidation({|oCtrl |
CheckTitleOk(oCtrl)})
SELFDCTyp1:FieldSpec:AppendValidation({|
oCtrl,cCatDescription,cRequired|
CheckCatCodeExists(oCtrl,cCatDescription,cRequired )},NAME_POSITION,"NO")
SELFDCTyp2:FieldSpec:AppendValidation({|
oCtrl,cCatDescription,cRequired|
CheckCatCodeExists(oCtrl,cCatDescription,cRequired )},NAME_TYPE,"NO")
SELFDCEmail:FieldSpec:AppendValidation({|oCtrl|C heckEMailOk(oCtrl,
FALSE)})

SELFDCHANDLER:FieldSpec:AppendValidation({|oCtrl |
CheckNameExists(oCtrl, FALSE)}) // rgtr 131109 per mike !
SELFDCSUBSET:FieldSpec:AppendValidation({|oCtrl|
CheckNameExists(oCtrl, FALSE)})


SELF:AllTrigDirty:=TRUE
SELF:lValidationOn:=TRUE
SELF:ActivateEditChange:=TRUE

SELF:aTrigRefText:={#NAMEX, #NAMEREF}

SELF:SetScr()

RETURN NIL
METHOD RefreshText(symName) CLASS NamesEdit

IF symName == #NAMEREF .OR. symName == #NAMEX
IF sUserAction==#NEW // .AND. ! SysObject():GetParam(NameRefType) ==
'A'
SELFCCGetRef:Show()
IF Len(StrTran(SELFDCNAMEX:Value,' ','')) > 3 .AND.
Empty(SELFDCNameREf:VALUE)
SELFCCGetRef:Enable()
ELSE
SELFCCGetRefisable()
ENDIF
ELSE
SELFCCGetRef:Hide()
ENDIF
ENDIF

IF symName == #EMAIL

ENDIF

RETURN NIL // rgtr 190507

if you would like the whole lot ... email me ...

but what i suggest is that you start very slowly and build your self a
library of what you need

we also have bbrowser modifications so that you can search in a browse
and display messages. but it has taken many people and many years to
get to this.

Dr Paolo Kalc (Calzi) is the man who assembled what we have now. and
all i can say is that it is very fast, very flexible, and works.

you can download a free trial of tdoc to see what can be done. email
me for details
you can see our manual www.tdocplus.co.uk/tdoc_manual - there are a
few links which are in error - as the new server is linux and case
sensitive - whereas we used not to be case sensitive. ouch ...

richard
Reply With Quote
  #6 (permalink)  
Old 05-31-2011, 10:00 AM
D.J.W. van Kooten
Guest
 
Posts: n/a
Default Re: Field validation

On Mon, 30 May 2011 15:09:28 -0700 (PDT), Krystian <softb@softb.pl>
wrote:

>On May 30, 1:31*pm, D.J.W. van Kooten <pub...@ic2remove.this.com>
>wrote:


Hello Krystian,
>
>1/ I can not put the validation code into EditFocusChange - it hangs
>the whole application.


That happens when you ommit the Gotfocus info. That makes sure that it
is only checked when you either enter or leave the control, not that
any change you make while you ar IN the control again call your code
in EditFocusChange indefinitely, so your application hangs.

Dick
Reply With Quote
  #7 (permalink)  
Old 05-31-2011, 01:52 PM
Karl Faller
Guest
 
Posts: n/a
Default Re: Field validation

Dick,
>not that
>any change you make while you ar IN the control

IMHO that shouldn't happen - you are in EditFOCUSChange, not in
EditChange...

Karl
Reply With Quote
  #8 (permalink)  
Old 05-31-2011, 10:20 PM
D.J.W. van Kooten
Guest
 
Posts: n/a
Default Re: Field validation

On Tue, 31 May 2011 15:52:42 +0200, Karl Faller
<k.faller_withoutthat_@onlinehome.de> wrote:

Hello Karl,

>IMHO that shouldn't happen - you are in EditFOCUSChange, not in
>EditChange...
>

It shouldn't indeed but try to add some code to the Editfocuschange
without that lGotfocus condition and you get exactly what Krystian
describes: he program hangs due to indefinite calls.

Dick
Reply With Quote
  #9 (permalink)  
Old 06-01-2011, 07:23 AM
Karl Faller
Guest
 
Posts: n/a
Default Re: Field validation

Dick,
make a BasicDlg from Sample. Add some sles

Add a module:
CLASS dlg_EFC INHERIT MainDialog

METHOD EditFocusChange(oE) CLASS dlg_EFC
SELF:caption += "HU"
SELF:test()

RETURN SUPER:EditFocusChange(oE)

METHOD test() CLASS dlg_EFC
RETURN "X"


change Start to use the inherited dlg.

I see my caption change whenever i enter or one of the sles, but NOT
when i type anything into them.

Just to make sure i didn't miss something, i even repeated the above
for a datawindow, whith the same result...

So?

Karl
>
>>IMHO that shouldn't happen - you are in EditFOCUSChange, not in
>>EditChange...
>>

>It shouldn't indeed but try to add some code to the Editfocuschange
>without that lGotfocus condition and you get exactly what Krystian
>describes: he program hangs due to indefinite calls.
>
>Dick

Reply With Quote
  #10 (permalink)  
Old 06-01-2011, 08:16 AM
richard.townsendrose
Guest
 
Posts: n/a
Default Re: Field validation

Guys

EditFocusChange is what it says.

EditChange is what it says.

We use a generic EditChange to run our "dirty" system - including
making other tabs not selectable
We use EditFocusChange to do two things
a) to call "RefreshText(symName)" for screen updating as the example
by Karl
b) to call the field validation system which calls a function with
parameters. other controls, data tables can be passed for date
comparisons etc

regards

richard

FUNCTION CheckDatePairOk(oCtrl,sleSecondDate,lIf2ndLater)
LOCAL nDate1 AS LONGINT
LOCAL nDate2 AS LONGINT
LOCAL lResult:=TRUE AS LOGIC

nDate1:=LONG(_CAST, oCtrl:Value)
ndate2:=LONG(_CAST, sleSecondDate:Value)

IF Empty(oCTRL:Value) .OR. Empty(sleSecondDate:Value) // nothing to
check
lResult:=TRUE
ELSE
IF lIf2ndLater // then date1 should be less or equal to date2
IF nDate1 > nDate2
lResult:=FALSE
ENDIF
ELSE // else date2 should be less or equal to date1
IF nDate2 > nDate1
lResult:=FALSE
ENDIF
ENDIF
ENDIF

IF lResult
RETURN NULL_OBJECT
ELSE
RETURN
HyperLabel{#Error,LoadResString('Error',IDG_ERROR, nPLH),LoadResString('Date
Range reversed - not valid',IDK_DATERANGEREVERSEDNOTVALID,nPLH)}
ENDIF

RETURN NULL_OBJECT
Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 09:19 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.