Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #12041 > unrolled thread

Validate codeblock

Started byZodcomagGmbH@yahoo.com
First post2018-10-10 12:43 -0700
Last post2018-10-12 04:25 -0700
Articles 9 — 3 participants

Back to article view | Back to comp.lang.clipper.visual-objects


Contents

  Validate codeblock ZodcomagGmbH@yahoo.com - 2018-10-10 12:43 -0700
    Re: Validate codeblock "Jamal" <noooospam@example.com> - 2018-10-10 23:10 -0400
    Re: Validate codeblock ZodcomagGmbH@yahoo.com - 2018-10-11 02:16 -0700
      Re: Validate codeblock "Jamal" <noooospam@example.com> - 2018-10-11 12:20 -0400
      Re: Validate codeblock Leo_Bond <l.bond@bk.ru> - 2018-10-11 11:13 -0700
        Re: Validate codeblock ZodcomagGmbH@yahoo.com - 2018-10-11 11:55 -0700
    Re: Validate codeblock ZodcomagGmbH@yahoo.com - 2018-10-11 11:15 -0700
      Re: Validate codeblock "Jamal" <noooospam@example.com> - 2018-10-12 00:48 -0400
        Re: Validate codeblock ZodcomagGmbH@yahoo.com - 2018-10-12 04:25 -0700

#12041 — Validate codeblock

FromZodcomagGmbH@yahoo.com
Date2018-10-10 12:43 -0700
SubjectValidate codeblock
Message-ID<d759701d-667c-4baa-8074-3369aedcb190@googlegroups.com>
If the customer wants to "Replace()", he enters a "For" condition, which I transfer into a codeblock with:
   bFor := &("{||"+cFor+"}")

If the client enters illegal "For" (for example a field name misspell), the "Replace" crashes the program.

1. Can I validate the codeblock before the Replace() ?
2. I tried to envelope the "Replace" with Begin Sequence & Recover.
   It still crashes.

Thanks for any help
Henry

[toc] | [next] | [standalone]


#12042

From"Jamal" <noooospam@example.com>
Date2018-10-10 23:10 -0400
Message-ID<ppmeui$a19$1@news.albasani.net>
In reply to#12041
Eval the code block in the begin sequence block:

Code snippet:

BEGIN SEQUENCE
         bFor := &("{||"+cFor+"}")
         Eval(bFor)
          lSuccess := TRUE
RECOVER
          lSuccess := FALSE
END SEQUENCE


Jamal

wrote in message 
news:d759701d-667c-4baa-8074-3369aedcb190@googlegroups.com...

If the customer wants to "Replace()", he enters a "For" condition, which I 
transfer into a codeblock with:
   bFor := &("{||"+cFor+"}")

If the client enters illegal "For" (for example a field name misspell), the 
"Replace" crashes the program.

1. Can I validate the codeblock before the Replace() ?
2. I tried to envelope the "Replace" with Begin Sequence & Recover.
   It still crashes.

Thanks for any help
Henry 

[toc] | [prev] | [next] | [standalone]


#12045

FromZodcomagGmbH@yahoo.com
Date2018-10-11 02:16 -0700
Message-ID<5e6ec8c3-a164-4c3f-ba4d-641072a79479@googlegroups.com>
In reply to#12041
Jamal thanks, but nothing changes.
The crash is now on the eVal (ErrorCode 14, Variable does not exist),

Cancelling the ErrorBox, the next statement is: 
   l Success := True 

---
I also tried oServer:eVal(bKod)
same result.

Thanks
Henry

[toc] | [prev] | [next] | [standalone]


#12046

From"Jamal" <noooospam@example.com>
Date2018-10-11 12:20 -0400
Message-ID<ppnt81$dio$1@news.albasani.net>
In reply to#12045
Please provide your full code that shows the issue.

Jamal

wrote in message 
news:5e6ec8c3-a164-4c3f-ba4d-641072a79479@googlegroups.com...

Jamal thanks, but nothing changes.
The crash is now on the eVal (ErrorCode 14, Variable does not exist),

Cancelling the ErrorBox, the next statement is:
   l Success := True

---
I also tried oServer:eVal(bKod)
same result.

Thanks
Henry 

[toc] | [prev] | [next] | [standalone]


#12047

FromLeo_Bond <l.bond@bk.ru>
Date2018-10-11 11:13 -0700
Message-ID<3eb2cb1f-0fbd-4767-830b-fa43f9e1091e@googlegroups.com>
In reply to#12045
четверг, 11 октября 2018 г., 12:16:17 UTC+3 пользователь Zodcom...@yahoo.com написал:
> Jamal thanks, but nothing changes.
> The crash is now on the eVal (ErrorCode 14, Variable does not exist),
> 
> Cancelling the ErrorBox, the next statement is: 
>    l Success := True 
> 
> ---
> I also tried oServer:eVal(bKod)
> same result.
> 
> Thanks
> Henry

Hi, Henry.
As far as I can understand "cFor" must follow some kind of rules according to the buisness logic of your app. Hence, you have to provide a kind of validation routine for this "cFor" expression, run it before codeblock is created and inform a user if there is some kind of mistake.
Or create a list of predefined "cFors" if it is possible. In any other case there will be errors, misspells and so on if a value for "cFor" is written by a human.
IMHO, of course.

[toc] | [prev] | [next] | [standalone]


#12049

FromZodcomagGmbH@yahoo.com
Date2018-10-11 11:55 -0700
Message-ID<92150cc0-8a80-450d-865b-b90d4c57b749@googlegroups.com>
In reply to#12047
Leo_Bond thanks

I hoped that there exists such validation.
And in any case, the "Begin Sequence" will keep the program from crashing.

Henry

[toc] | [prev] | [next] | [standalone]


#12048

FromZodcomagGmbH@yahoo.com
Date2018-10-11 11:15 -0700
Message-ID<c4dafee6-bd5e-47d5-904e-32762fafd0cd@googlegroups.com>
In reply to#12041
Jamal thanls.

METHOD Replace_PB() CLASS dBase_Replace
   Local lRep, lEval as Logic
   Local iField, nOldRecNo as dword
   Local nNewField as Float 
   Local bFor as _CodeBlock
   Local cField, cFor, cNewField, cType, sOldTag as String
   Local oTB as TextBox

   /* ComboField is filled with all the fields of oNew */
   cField    := self:oDCmField_CB:CurrentItem
   iField    := self:oDCmField_CB:Value
   cNewField := self:oDCmField_SLE:TextValue
   
   cType := self:oNew:FieldInfo(DBS_TYPE, iField)
   cFor := self:oDCmFor:TextValue
   if Empty(cFor)
      oTB := TextBox{self, "Replace", "All records will be replaced - OK?"}
      oTB:Type := BOXICONQUESTIONMARK + BUTTONYESNO
      IF (oTB:Show() = BOXREPLYNO)
         RETURN nil
      ENDIF
   endif	

   *  if indexed field is changed, the run can go crazy
   /*
   IF ! Empty(oServer:OrderInfo(DBOI_SCOPETOP))
      OldTopScope := oServer:OrderInfo(DBOI_SCOPETOP)
   ELSE
      OldTopScope := null_string
   ENDIF

   IF ! Empty(oServer:OrderInfo(DBOI_SCOPEBOTTOM))
      OldBottomScope := oServer:OrderInfo(DBOI_SCOPEBOTTOM)
   ELSE
      OldBottomScope := null_string
   ENDIF
   */

   sOldTag   := self:oNew:OrderInfo(DBOI_NAME)
   nOldRecNo := self:oNew:RecNo
   self:oNew:SetOrder(0)	

   if Empty(cFor)
      bFor := &("{||.t.}" )
   else
      bFor := &("{||" + cFor + "}")
   endif	     
	
   begin sequence
      Eval(bFor)   // programm crashed with "variable does not exist)
      // tried also:    self:oNew:Eval(bFor)
      lEval := true
   recover
      lEval := False
   end sequence	

   if !lEval
      ErrorBox{self, '"For" not valid'}:Show()
   else		
      if cType = "C"	
         lRep := self:oNew:Replace( {||cNewField}, cField, bFor,,DBSCOPEALL)

      elseif cType = "N"  
         nNewField := Val(cNewField)
         lRep := self:oNew:Replace( {||nNewField}, cField, bFor,,DBSCOPEALL)
      endif
	
      if !lRep
          ErrorBox{self, "Change unseccessful"}:Show()
      endif
   endif		

   * -- Back to the bfuture -------------
   /*
   IF ! Empty(OldBottomScope)
      oServer:OrderScope(BottomScope, OldBottomScope)
   ELSE
      oServer:OrderScope(BottomScope, nil)
   ENDIF
   */

   IF Empty(sOldTag)
      self:oNew:SetOrder(0)
   ELSE
      self:oNew:SetOrder(sOldTag)
   ENDIF
	
   IF nOldRecNo > 0 .and. nOldRecNo <= self:oNew:RecCount
      self:oNew:GoTo(nOldRecNo)
   ENDIF
	
   G_oWindow:BroadCastMessage(self, #dBase_Replace, self:nRecNo)
    self:EndWindow()

   RETURN nil
	


   

[toc] | [prev] | [next] | [standalone]


#12051

From"Jamal" <noooospam@example.com>
Date2018-10-12 00:48 -0400
Message-ID<ppp92i$npd$1@news.albasani.net>
In reply to#12048
The way you wrote the code does NOT handle any error, you are leaving it the 
VO error handling system. BEGIN/END SEQUENCE by itself does not do anything.

You need to use ErrorBlock() which allows you to override this default error 
handling mechanism with yours.

Check the VO documentation about error handling. Search for ErrorBlock

In your case:

Use a function like the following:


FUNCTION VerifyCondition(sCondition AS STRING) AS LOGIC PASCAL
LOCAL cbCodeBlock AS _CODEBLOCK   // class
LOCAL cbSaveHandler AS CODEBLOCK
LOCAL lSuccess  AS LOGIC

    cbSaveHandler := ErrorBlock({|x| _Break(x)})    // just break
    BEGIN SEQUENCE
         cbCodeBlock :=  &( [{||] + sCondition + [}] )
         Eval(cbCodeBlock)
          lSuccess := TRUE   // if we get here, the condition is valid
    RECOVER
          lSuccess := FALSE
     END SEQUENCE
     ErrorBlock(cbSaveHandler)

RETURN lSuccess

So, in your code
if empty(cFor)
    sCondition := ".T."
endif

If !VerifyCondition(cFor)
   // display error message
endif

Customize the function to your needs.

Jamal

wrote in message 
news:c4dafee6-bd5e-47d5-904e-32762fafd0cd@googlegroups.com...

Jamal thanls.

METHOD Replace_PB() CLASS dBase_Replace
   Local lRep, lEval as Logic
   Local iField, nOldRecNo as dword
   Local nNewField as Float
   Local bFor as _CodeBlock
   Local cField, cFor, cNewField, cType, sOldTag as String
   Local oTB as TextBox

   /* ComboField is filled with all the fields of oNew */
   cField    := self:oDCmField_CB:CurrentItem
   iField    := self:oDCmField_CB:Value
   cNewField := self:oDCmField_SLE:TextValue

   cType := self:oNew:FieldInfo(DBS_TYPE, iField)
   cFor := self:oDCmFor:TextValue
   if Empty(cFor)
      oTB := TextBox{self, "Replace", "All records will be replaced - OK?"}
      oTB:Type := BOXICONQUESTIONMARK + BUTTONYESNO
      IF (oTB:Show() = BOXREPLYNO)
         RETURN nil
      ENDIF
   endif

   *  if indexed field is changed, the run can go crazy
   /*
   IF ! Empty(oServer:OrderInfo(DBOI_SCOPETOP))
      OldTopScope := oServer:OrderInfo(DBOI_SCOPETOP)
   ELSE
      OldTopScope := null_string
   ENDIF

   IF ! Empty(oServer:OrderInfo(DBOI_SCOPEBOTTOM))
      OldBottomScope := oServer:OrderInfo(DBOI_SCOPEBOTTOM)
   ELSE
      OldBottomScope := null_string
   ENDIF
   */

   sOldTag   := self:oNew:OrderInfo(DBOI_NAME)
   nOldRecNo := self:oNew:RecNo
   self:oNew:SetOrder(0)

   if Empty(cFor)
      bFor := &("{||.t.}" )
   else
      bFor := &("{||" + cFor + "}")
   endif

   begin sequence
      Eval(bFor)   // programm crashed with "variable does not exist)
      // tried also:    self:oNew:Eval(bFor)
      lEval := true
   recover
      lEval := False
   end sequence

   if !lEval
      ErrorBox{self, '"For" not valid'}:Show()
   else
      if cType = "C"
         lRep := self:oNew:Replace( {||cNewField}, cField, bFor,,DBSCOPEALL)

      elseif cType = "N"
         nNewField := Val(cNewField)
         lRep := self:oNew:Replace( {||nNewField}, cField, bFor,,DBSCOPEALL)
      endif

      if !lRep
          ErrorBox{self, "Change unseccessful"}:Show()
      endif
   endif

   * -- Back to the bfuture -------------
   /*
   IF ! Empty(OldBottomScope)
      oServer:OrderScope(BottomScope, OldBottomScope)
   ELSE
      oServer:OrderScope(BottomScope, nil)
   ENDIF
   */

   IF Empty(sOldTag)
      self:oNew:SetOrder(0)
   ELSE
      self:oNew:SetOrder(sOldTag)
   ENDIF

   IF nOldRecNo > 0 .and. nOldRecNo <= self:oNew:RecCount
      self:oNew:GoTo(nOldRecNo)
   ENDIF

   G_oWindow:BroadCastMessage(self, #dBase_Replace, self:nRecNo)
    self:EndWindow()

   RETURN nil


[toc] | [prev] | [next] | [standalone]


#12056

FromZodcomagGmbH@yahoo.com
Date2018-10-12 04:25 -0700
Message-ID<9ccff8cd-e6a8-48a9-acb7-fb7b6b4388b5@googlegroups.com>
In reply to#12051
Jamal thanks

Ofcourse, I forgot the ErrorBlock (my default errorblock _Quit)

Henry

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.clipper.visual-objects


csiph-web