Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.clipper.visual-objects > #12051
| From | "Jamal" <noooospam@example.com> |
|---|---|
| Newsgroups | comp.lang.clipper.visual-objects |
| Subject | Re: Validate codeblock |
| Date | 2018-10-12 00:48 -0400 |
| Organization | albasani.net |
| Message-ID | <ppp92i$npd$1@news.albasani.net> (permalink) |
| References | <d759701d-667c-4baa-8074-3369aedcb190@googlegroups.com> <c4dafee6-bd5e-47d5-904e-32762fafd0cd@googlegroups.com> |
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
Back to comp.lang.clipper.visual-objects | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web