Page 1 of 1
special Codeblock Syntax under Fivewin
Posted: Mon Nov 07, 2022 7:16 am
by Jimmy
hi,
i saw in some Code Syntax like this
Code: Select all | Expand
<||
local oRect := oDlg: GetCliRect ( )
oBar: nWidth := oRect: nWidth
oLbx: nWidth := oRect: nWidth - 210
RETURN NIL
>
where can i read "more" about this Syntax
in above Sample you need to pass oLbx as Parameter but how using that Syntax
---
here a Sample how i pass Parameter to Codeblock
Code: Select all | Expand
#include "FiveWin.ch"
PROCEDURE MAIN
LOCAL a := 1
LOCAL b := "a"
LOCAL cBlock, bBlock
// you can per-build Codeblock as String
cBlock := "{|a,b| DoTest(a,b)}"
bBlock := &(cBlock)
Eval(bBlock,a,b)
return
Code: Select all | Expand
FUNCTION DoTest(a,b)
? a, VALTYPE(a)
? b, VALTYPE(b)
RETURN 0
as you can see i include Parameter between "|" (Pipe) Sign of Codeblock and pass them at EVAL()
Re: special Codeblock Syntax under Fivewin
Posted: Mon Nov 07, 2022 8:11 am
by hmpaquito
Hi Mr. Jimmy,
They are named extended codeblocks
https://vivaclipper.wordpress.com/tag/codeblock/
This (extra) syntax too is correct for harbour:
Regards
Re: special Codeblock Syntax under Fivewin
Posted: Mon Nov 07, 2022 10:02 am
by hua
This is xHarbour style of extended codeblock
Code: Select all | Expand
<|oLbx|
local oRect := oDlg: GetCliRect ( )
oBar: nWidth := oRect: nWidth
oLbx: nWidth := oRect: nWidth - 210
RETURN NIL
>
Harbour style
Code: Select all | Expand
{|oLbx|
local oRect := oDlg: GetCliRect ( )
oBar: nWidth := oRect: nWidth
oLbx: nWidth := oRect: nWidth - 210
RETURN NIL
}
Just remember that extended codeblock must have RETURN
http://harbouradvisor.blogspot.com/2011 ... locks.html
Re: special Codeblock Syntax under Fivewin
Posted: Mon Nov 07, 2022 10:39 am
by hmpaquito
Hi Hua,
Just remember that extended codeblock must have RETURN
It's not required return clause. Return clause it's neccessary only for return value
Code: Select all | Expand
// Not neccessary return value. Only code. Implicity return value is NIL
x:= {||
a:= 1
b:= 2
c:= 3
}
// Return value
y:= {||
a:= 1
b:= 2
c:= 3
return b
}
Regards
Re: special Codeblock Syntax under Fivewin
Posted: Mon Nov 07, 2022 11:56 am
by Jimmy
hi,
thx all for Answer
hmpaquito wrote:It's not required return clause. Return clause it's neccessary only for return value
ah, that was what have confuse me
Re: special Codeblock Syntax under Fivewin
Posted: Mon Nov 07, 2022 2:27 pm
by cnavarro
Dear Jimmy
This syntax for codeblock, RETURN is required
Code: Select all | Expand
local bBlock
bBlock := <||
local a := 1
local b := 2
local c := 3
Return nil
>
Re: special Codeblock Syntax under Fivewin
Posted: Mon Nov 07, 2022 3:59 pm
by hmpaquito
Estimado Cristóbal,
La siguiente, sin return, es una sintaxis válida, que dará NIL como resultado de la operación Eval( bBlock )
Code: Select all | Expand
local bBlock
bBlock := <||
local a := 1
local b := 2
local c := 3
>
Atte.
Re: special Codeblock Syntax under Fivewin
Posted: Mon Nov 07, 2022 8:40 pm
by cnavarro
Estimadísimo Paquito
Yo es que soy un poco perfeccionista y como al no tener RETURN me da el siguiente mensaje ( tengo los warnings activados ) y como sabemos un codeblock es tratado internamente como si fuese una FUNCTION
Anonymous
D:\FWH\FWHTEAM\SAMPLES\testtoast.prg(17) Warning W0007 Function '{||...}' does not end with RETURN statement
Compilation Errors
Link Error
Re: special Codeblock Syntax under Fivewin
Posted: Mon Nov 07, 2022 9:06 pm
by hmpaquito
Hola Cristóbal,
Pues sí. Debe ser como tu dices: Los warning mandan y definen la sintaxis correcta.
Así en "stricto sensu" hay que poner un return en los extended codeblocks
Gracias por la aclaración
Re: special Codeblock Syntax under Fivewin
Posted: Tue Nov 08, 2022 2:27 am
by nageswaragunupudi
It's not required return clause. Return clause it's neccessary only for return value
"Return" is not required with xHarbour.
"Return" is required with Harbour.
So it is always safe to use return <someval> or return nil.
Our program should with both with Harbour and xHarbour.
It is always a good idea to keep our programs compatible with both Harbour and xHarbour and this is a must for us the FWteam.
It is safe to use this template:
xHarbour:
Angular brackets is the right syntax for xHarbour and the return statement does not hurt xHarbour
Harbour:
Fivewin.ch translates the angular brackets ( < .. > ) to curly braces ( {..} ) when using Harbour and we also comply with the requirement of return statement.
Adantage of the extended codeblock syntax is that, we can use local variables and use commands like a normal program.
Re: special Codeblock Syntax under Fivewin
Posted: Tue Nov 08, 2022 8:31 am
by hmpaquito
Thank you very much Mr. Rao for your extense y comprensive explication