special Codeblock Syntax under Fivewin

Post Reply
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

special Codeblock Syntax under Fivewin

Post 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()
greeting,
Jimmy
hmpaquito
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: special Codeblock Syntax under Fivewin

Post by hmpaquito »

Hi Mr. Jimmy,

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


This (extra) syntax too is correct for harbour:

Code: Select all | Expand

{|| 
      a:= 1
      b:= 2
      c:= 3 
 }
Regards
hua
Posts: 1075
Joined: Fri Oct 28, 2005 2:27 am
Has thanked: 1 time
Been thanked: 1 time

Re: special Codeblock Syntax under Fivewin

Post 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
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hmpaquito
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: special Codeblock Syntax under Fivewin

Post 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
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

Re: special Codeblock Syntax under Fivewin

Post 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
greeting,
Jimmy
User avatar
cnavarro
Posts: 6557
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Been thanked: 3 times

Re: special Codeblock Syntax under Fivewin

Post 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
               >

 
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
hmpaquito
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: special Codeblock Syntax under Fivewin

Post 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.
User avatar
cnavarro
Posts: 6557
Joined: Wed Feb 15, 2012 8:25 pm
Location: España
Been thanked: 3 times

Re: special Codeblock Syntax under Fivewin

Post 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
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
hmpaquito
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: special Codeblock Syntax under Fivewin

Post 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
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: special Codeblock Syntax under Fivewin

Post 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:

Code: Select all | Expand

< |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
hmpaquito
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: special Codeblock Syntax under Fivewin

Post by hmpaquito »

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