Array need @ when use in VALID ?

Array need @ when use in VALID ?

Postby Jimmy » Sat Nov 05, 2022 9:17 am

hi,

i want to get Information when logoff from App and use VALID in ACTIVATE

Code: Select all  Expand view
LOCAL oFont, aRect, lRet := .T.

   ACTIVATE WINDOW oMain ON INIT ... ;
      VALID ( lRet := DoEndProc(oMain,@aRect), lRet ) CENTER

   cRow     := VAR2CHAR(aRect[1])
   cCol     := VAR2CHAR(aRect[2])
   cHeight  := VAR2CHAR(aRect[3])
   cWidth   := VAR2CHAR(aRect[4])
   // save to INI
   LoadConfig( @cRow, @cCol, @cWidth, @cHeight, ... )


Code: Select all  Expand view
STATIC FUNCTION DoEndProc(oMain,aRect)
   aRect := oMain:GetRect()
   FWLOG aRect
RETURN .T.


when not use @ Reference i got empty Array :shock: while FWLOG show Data ... hm ... :?

is this "normal" under Fivewin that i must pass Array per Reference :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Array need @ when use in VALID ?

Postby Enrico Maria Giordano » Sat Nov 05, 2022 9:39 am

Array is always passed by reference. If you use @, you are passing a reference to the array variable that allows you to assign it to a new array:

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL aArray := { 1, 2, 3, 4 }

    TEST1( aArray )

    ? aArray

    TEST2( @aArray )

    ? aArray

    RETURN NIL


STATIC FUNCTION TEST1( aArray )

    aArray = { "A", "B" } // This is a local variable so the assign is lost at the end of the function

    RETURN NIL


STATIC FUNCTION TEST2( aArray )

    aArray = { "C", "D" } // This is a variable passed by reference so the assign is made to the original array variable

    RETURN NIL
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Array need @ when use in VALID ?

Postby Jimmy » Sat Nov 05, 2022 9:55 am

hi Enrico,

under Xbase++ and HMG i do not need @ Reference for Array so i was confuse about Fivewin
now i have to rewrite all CODE where i have pass Array to use @
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Array need @ when use in VALID ?

Postby Enrico Maria Giordano » Sat Nov 05, 2022 10:01 am

No, Fivewin has nothing to do with this subject. Normally, you haven't to pass array with @, I never used it. Please show a sample of your problem.
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Array need @ when use in VALID ?

Postby Jimmy » Sat Nov 05, 2022 10:24 am

hi Enrico,

try this (without @ Reference)
Code: Select all  Expand view
#include "Fivewin.ch"
PROCEDURE Main()
LOCAL oMain, aRect := {0,0,0,0}, lRet := .T.
LOCAL nHeight   := 1024
LOCAL nWidth    := 1280
LOCAL nTop      := 0
LOCAL nLeft     := 0

   DEFINE WINDOW oMain FROM 0,0 TO nHeight, nWidth PIXEL TITLE "FiveWin TGrid Listview Demo "

   ACTIVATE WINDOW oMain  VALID ( lRet := DoEndProco(oMain, aRect), lRet ) CENTER

   MsgInfo( hb_valToExp(aRect) )

RETURN

STATIC FUNCTION DoEndProco(oMain,aRect)
   aRect := oMain:GetRect()
RETURN .T.
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Array need @ when use in VALID ?

Postby Enrico Maria Giordano » Sat Nov 05, 2022 10:54 am

Code: Select all  Expand view
STATIC FUNCTION DoEndProco(oMain,aRect)
   aRect[ 1 ] := oMain:GetRect()[ 1 ]
   aRect[ 2 ] := oMain:GetRect()[ 2 ]
   aRect[ 3 ] := oMain:GetRect()[ 3 ]
   aRect[ 4 ] := oMain:GetRect()[ 4 ]
RETURN .T.
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Array need @ when use in VALID ?

Postby Jimmy » Sun Nov 06, 2022 5:37 am

hi Enrico,

thx for Solution

it also work when pass Array per @ Reference in "Original" CODE

but my Question was why my "Original" Sample does not work without @ Reference (or Workaround) :?:
have it to do with VALID :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Array need @ when use in VALID ?

Postby Enrico Maria Giordano » Sun Nov 06, 2022 8:22 am

The explanation is in my sample on the second message of this thread. If you are asking something else then please show a sample of the problem.
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Array need @ when use in VALID ?

Postby Jimmy » Sun Nov 06, 2022 9:43 am

hi Enrico,

i think i know how to use Array but i never have use it with "VALID"

so i got [0,0,0,0} on 1st try ... hm ...
Code: Select all  Expand view
VALID ( lRet := DoEndProc(oMain,aRect), lRet ) CENTER

after change to
Code: Select all  Expand view
VALID ( lRet := DoEndProc(oMain,@aRect), lRet ) CENTER

it work ... hm ...

so my Question is : why 1st Version fail :?: have it to do with VALID :?:
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1732
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Array need @ when use in VALID ?

Postby Enrico Maria Giordano » Sun Nov 06, 2022 10:22 am

No, it has to do with the normal passing-parameters behavior.
User avatar
Enrico Maria Giordano
 
Posts: 8715
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 73 guests