FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour special Codeblock Syntax under Fivewin
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
special Codeblock Syntax under Fivewin
Posted: Mon Nov 07, 2022 07:16 AM
hi,

i saw in some Code Syntax like this
Code (fw): Select all Collapse
 <||
聽 聽 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 (fw): Select all Collapse
#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 (fw): Select all Collapse
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()
greeting,

Jimmy
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: special Codeblock Syntax under Fivewin
Posted: Mon Nov 07, 2022 08:11 AM
Hi Mr. Jimmy,

They are named extended codeblocks
https://vivaclipper.wordpress.com/tag/codeblock/


This (extra) syntax too is correct for harbour:
Code (fw): Select all Collapse
{|| 
聽 聽 聽 a:= 1
聽 聽 聽 b:= 2
聽 聽 聽 c:= 3 
聽}
Regards
Posts: 1096
Joined: Fri Oct 28, 2005 02:27 AM
Re: special Codeblock Syntax under Fivewin
Posted: Mon Nov 07, 2022 10:02 AM
This is xHarbour style of extended codeblock
Code (fw): Select all Collapse
<|oLbx|
聽 聽 local oRect := oDlg: 聽GetCliRect 聽( 聽)
聽 聽 聽 聽oBar: 聽nWidth := oRect: 聽nWidth
聽 聽 聽 聽oLbx: 聽nWidth := oRect: 聽nWidth - 聽 210
聽 聽 RETURN 聽 NIL
聽>
Harbour style
Code (fw): Select all Collapse
{|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/09/extended-codeblocks.html
FWH 11.08/FWH 19.12

BCC5.82/BCC7.3

xHarbour/Harbour
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: special Codeblock Syntax under Fivewin
Posted: Mon Nov 07, 2022 10:39 AM
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 (fw): Select all Collapse
// 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
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: special Codeblock Syntax under Fivewin
Posted: Mon Nov 07, 2022 11:56 AM
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
greeting,

Jimmy
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: special Codeblock Syntax under Fivewin
Posted: Mon Nov 07, 2022 02:27 PM
Dear Jimmy
This syntax for codeblock, RETURN is required
Code (fw): Select all Collapse
聽 聽local bBlock
聽 聽bBlock 聽:= <|| 
聽 聽 聽 聽 聽 聽 聽 聽 聽 local a := 1
聽 聽 聽 聽 聽 聽 聽 聽 聽 local b := 2
聽 聽 聽 聽 聽 聽 聽 聽 聽 local c := 3
聽 聽 聽 聽 聽 聽 聽 聽 聽 Return nil
聽 聽 聽 聽 聽 聽 聽 聽>
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noci贸n del tiempo

El secreto de la felicidad no est谩 en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: special Codeblock Syntax under Fivewin
Posted: Mon Nov 07, 2022 03:59 PM
Estimado Crist贸bal,

La siguiente, sin return, es una sintaxis v谩lida, que dar谩 NIL como resultado de la operaci贸n Eval( bBlock )

Code (fw): Select all Collapse
 local bBlock
聽 聽bBlock 聽:= <||
聽 聽 聽 聽 聽 聽 聽 聽 聽 local a := 1
聽 聽 聽 聽 聽 聽 聽 聽 聽 local b := 2
聽 聽 聽 聽 聽 聽 聽 聽 聽 local c := 3
聽 聽 聽 聽 聽 聽 聽 聽>
Atte.
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: special Codeblock Syntax under Fivewin
Posted: Mon Nov 07, 2022 08:40 PM
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
Cristobal Navarro

Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noci贸n del tiempo

El secreto de la felicidad no est谩 en hacer lo que te gusta, sino en que te guste lo que haces
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: special Codeblock Syntax under Fivewin
Posted: Mon Nov 07, 2022 09:06 PM

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

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: special Codeblock Syntax under Fivewin
Posted: Tue Nov 08, 2022 02:27 AM
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:
Code (fw): Select all Collapse
< |params,..|
聽 // code
聽 return any
>
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.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: special Codeblock Syntax under Fivewin
Posted: Tue Nov 08, 2022 08:31 AM

Thank you very much Mr. Rao for your extense y comprensive explication

Continue the discussion