special Codeblock Syntax under Fivewin

special Codeblock Syntax under Fivewin

Postby Jimmy » Mon Nov 07, 2022 7:16 am

hi,

i saw in some Code Syntax like this

Code: Select all  Expand view
<||
    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 view
#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 view
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
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: special Codeblock Syntax under Fivewin

Postby hmpaquito » Mon Nov 07, 2022 8: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: Select all  Expand view
{||
      a:= 1
      b:= 2
      c:= 3
 }


Regards
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: special Codeblock Syntax under Fivewin

Postby hua » Mon Nov 07, 2022 10:02 am

This is xHarbour style of extended codeblock
Code: Select all  Expand view

<|oLbx|
    local oRect := oDlg:  GetCliRect  (  )
       oBar:  nWidth := oRect:  nWidth
       oLbx:  nWidth := oRect:  nWidth -   210
    RETURN   NIL
 >
 


Harbour style
Code: Select all  Expand view
{|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
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: special Codeblock Syntax under Fivewin

Postby hmpaquito » 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: Select all  Expand view
// 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
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: special Codeblock Syntax under Fivewin

Postby Jimmy » 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
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: special Codeblock Syntax under Fivewin

Postby cnavarro » Mon Nov 07, 2022 2:27 pm

Dear Jimmy
This syntax for codeblock, RETURN is required
Code: Select all  Expand view


   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
User avatar
cnavarro
 
Posts: 6548
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: special Codeblock Syntax under Fivewin

Postby hmpaquito » Mon Nov 07, 2022 3: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: Select all  Expand view
local bBlock
   bBlock  := <||
                  local a := 1
                  local b := 2
                  local c := 3
               >
 

Atte.
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: special Codeblock Syntax under Fivewin

Postby cnavarro » Mon Nov 07, 2022 8: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
User avatar
cnavarro
 
Posts: 6548
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: special Codeblock Syntax under Fivewin

Postby hmpaquito » Mon Nov 07, 2022 9: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
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: special Codeblock Syntax under Fivewin

Postby nageswaragunupudi » Tue Nov 08, 2022 2: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: Select all  Expand view

< |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
User avatar
nageswaragunupudi
 
Posts: 10641
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: special Codeblock Syntax under Fivewin

Postby hmpaquito » Tue Nov 08, 2022 8:31 am

Thank you very much Mr. Rao for your extense y comprensive explication
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 87 guests