Conversion from ca-clipper ( not found a variable)

Re: Conversion from ca-clipper ( not found a variable)

Postby Marc Venken » Thu Mar 03, 2022 9:49 pm

Very interesting ....

I see that I use a combination of Static, Local and Public.

Static (mostly because I see them on sample source code in the forum (Seems to be correct)
Public because I need them everywhere (It seems to be correct)
Local when needed I think... ))

BUT... I see a lot of warnings when I compile with the build from the samples dir (not in my setup) but will look into it.

I assume now that you guys will advice me to get rid of all the warning ? but please tell me the advantage or possible risks...

I also don't kill the objects like fonts, oDlg, ... I Mostly just end the program and all this stuff is gone ? At least I think so...




Oeps... My Warning log has 430 lines

test1.prg(1714) Warning W0027 Meaningless use of expression ':'
test1.prg(1714) Warning W0027 Meaningless use of expression 'Logical'
test1.prg(1716) Warning W0027 Meaningless use of expression ':'
test1.prg(1716) Warning W0027 Meaningless use of expression 'Logical'
test1.prg(1744) Warning W0001 Ambiguous reference 'DLG'
test1.prg(1757) Warning W0001 Ambiguous reference 'NSIZE'
test1.prg(1758) Warning W0001 Ambiguous reference 'NSIZE'
test1.prg(1823) Warning W0001 Ambiguous reference 'OBTNINDEXES'
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1452
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Conversion from ca-clipper ( not found a variable)

Postby Enrico Maria Giordano » Thu Mar 03, 2022 10:25 pm

Marc Venken wrote:I also don't kill the objects like fonts, oDlg, ... I Mostly just end the program and all this stuff is gone ? At least I think so...


Yes, all the objects are released at the end of the program. The problem arise when you create a resource inside a function and don't release it at the end: if that function is called n times then the resource is allocated n times and released zero times and you will have resource leakage.

Marc Venken wrote:test1.prg(1714) Warning W0027 Meaningless use of expression ':'
test1.prg(1714) Warning W0027 Meaningless use of expression 'Logical'
test1.prg(1716) Warning W0027 Meaningless use of expression ':'
test1.prg(1716) Warning W0027 Meaningless use of expression 'Logical'
test1.prg(1744) Warning W0001 Ambiguous reference 'DLG'
test1.prg(1757) Warning W0001 Ambiguous reference 'NSIZE'
test1.prg(1758) Warning W0001 Ambiguous reference 'NSIZE'
test1.prg(1823) Warning W0001 Ambiguous reference 'OBTNINDEXES'


Can I see the related lines of source code?

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

Re: Conversion from ca-clipper ( not found a variable)

Postby Marc Venken » Thu Mar 03, 2022 10:42 pm

( 1714 )DEFINE BUTTON OF oBar PROMPT "Filters Uit" RESOURCE "EDIT";
ACTION (oBrw:lGetBar = .F.,oBrw:refresh(),oBrw:setfocus() )
(1716 ) DEFINE BUTTON OF oBar PROMPT "Filters Aan" RESOURCE "EDIT";
ACTION (oBrw:lGetBar=.t.,oBrw:refresh(),oBrw:setfocus() )

DEFINE BUTTON OF oBar PROMPT "Mainbar.Exit" RESOURCE "exit" ;
ACTION Dlg:End() // This need to be oDlg

For nSize and oBtnindexes and for almost all others, I don't use any of the settings (Local, Public , ...)

I see why the warning, nSize is not set as local. But I see no visible problem or a program that is failing.

Code: Select all  Expand view  RUN

function XbrSetupbuttons( oBrw,cData )
  local cString:="", nOrder:=0
  do case
    case upper(oBrw:cAlias) = "BRWDETAIL"
      msginfo("Test Editsource")
      cString = brwdetail->brwnaam
      obrw:gobottom()
      nOrder = brwdetail->order + 10
      nSize = 100
      oBrw:EditSource(.T., "brwnaam,order,size" , { cString,nOrder,nSize })
      //cData = brwdetail->brwnaam
      //oBrw:add()
      //msginfo("BRWDETAIL")
    otherwise
      oBrw:EditSource(.t.)
  endcase

return NIL

 
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1452
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Conversion from ca-clipper ( not found a variable)

Postby Marc Venken » Thu Mar 03, 2022 10:45 pm

Enrico Maria Giordano wrote:
Marc Venken wrote:I also don't kill the objects like fonts, oDlg, ... I Mostly just end the program and all this stuff is gone ? At least I think so...


Yes, all the objects are released at the end of the program. The problem arise when you create a resource inside a function and don't release it at the end: if that function is called n times then the resource is allocated n times and released zero times and you will have resource leakage.

EMG


Indeed. I need to change that in my sources...
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1452
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Conversion from ca-clipper ( not found a variable)

Postby Enrico Maria Giordano » Thu Mar 03, 2022 10:52 pm

Marc Venken wrote:( 1714 )DEFINE BUTTON OF oBar PROMPT "Filters Uit" RESOURCE "EDIT";
ACTION (oBrw:lGetBar = .F.,oBrw:refresh(),oBrw:setfocus() )


Code: Select all  Expand view  RUN
oBrw:lGetBar := .F.


Otherwise it is not an assignment but an unuseful logical compare.

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

Re: Conversion from ca-clipper ( not found a variable)

Postby Marc Venken » Thu Mar 03, 2022 10:58 pm

In this code, I recently created I wonder if there is a potential risk of failure because the object oHttp is not ended somewhere into the loop ?
If so, there need to be a oHttp:end() afther the END . Is this the correct logic that I need to start using then ?



Code: Select all  Expand view  RUN

function testapi()  // part of code
  local cBuffer:=""
  local uResponse, cCookies, I, cLink, cUrl,oHttp

  do while !webshop->(eof())

    ... code for filling my API data into cBuffer

    msginfo(cBuffer)

    oHttp := FWGetOleObject( "WINHTTP.WinHttpRequest.5.1" )

      WITH OBJECT oHttp
         :SetTimeouts(0, 60000, 30000, 120000)
         :Open( "PATCH", cUrl, .f. )      // My Marc seen on Google
         :SetRequestHeader( "Accept",        "application/json" )
         :SetRequestHeader( "Content-Type",  "application/json" )
         :Send( cBuffer )
         :WaitForResponse()
         //if :status <> 200
            ? :Status, :StatusText // 200 OK
         //endif
      END

     webshop->(dbskip())
  enddo
RETURN

 
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1452
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Conversion from ca-clipper ( not found a variable)

Postby Marc Venken » Thu Mar 03, 2022 11:39 pm

Just to have a better understanding :

In this code (parts) , from the main function

the warning log says folowing :

test1.prg(72) Warning W0002 Ambiguous reference, assuming memvar 'LSERVER'
test1.prg(73) Warning W0002 Ambiguous reference, assuming memvar 'SERVER_PATH'
test1.prg(75) Warning W0002 Ambiguous reference, assuming memvar 'LOCAL_PATH'
test1.prg(81) Warning W0001 Ambiguous reference 'OCLP'

The warning for oClp I wonder : It is defined as public (I need it all over the program), but still a warning in the define clipboard line ?

Code: Select all  Expand view  RUN

FUNCTION Main()
   LOCAL sys_versie := "Jan 2022 - 01/01"
   //  more local
   PUBLIC lServer := .F.
   public SERVER_PATH := "\\CAROLIEN-PC\MARC\"
   public LOCAL_PATH  := "
c:\marc32\"
   Public sys_path
   Public oGetLev, oClp, hBrw, oArtChanges

   DEFINE CLIPBOARD oClp OF oWnd
   // ....
RETURN NIL

Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1452
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Conversion from ca-clipper ( not found a variable)

Postby Enrico Maria Giordano » Fri Mar 04, 2022 9:09 am

Marc Venken wrote:In this code, I recently created I wonder if there is a potential risk of failure because the object oHttp is not ended somewhere into the loop ?
If so, there need to be a oHttp:end() afther the END . Is this the correct logic that I need to start using then ?


xHarbour ends the OLE objects automatically (ie. oOle:End()) when the variables finish its lifetime. Maybe Harbour too but I'm not sure.

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

Re: Conversion from ca-clipper ( not found a variable)

Postby Enrico Maria Giordano » Fri Mar 04, 2022 9:14 am

Marc Venken wrote:test1.prg(72) Warning W0002 Ambiguous reference, assuming memvar 'LSERVER'


Where the PUBLIC or PRIVATE variable is used you have to use the MEMVAR declaration or the M -> prefix:

MEMVAR lServer

or

M -> lServer

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

Re: Conversion from ca-clipper ( not found a variable)

Postby Silvio.Falconi » Fri Mar 04, 2022 12:37 pm

Enrico Maria Giordano wrote:
Marc Venken wrote:test1.prg(72) Warning W0002 Ambiguous reference, assuming memvar 'LSERVER'


Where the PUBLIC or PRIVATE variable is used you have to use the MEMVAR declaration or the M -> prefix:

MEMVAR lServer

or

M -> lServer

EMG



ok but on my old clipper prg I assigned on "N"+ LTrim(Str(conta1)) a number

numeri:= 22

for a sample
do while (conta <= Val(numeri))
num:= "N" + LTrim(Str(conta))


so num = N1,N2,N3....
but &num can have different values

they are like variables but they are not declared (local, private, public, memvar)
can i know the value in any part of the program?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7090
Joined: Thu Oct 18, 2012 7:17 pm

Re: Conversion from ca-clipper ( not found a variable)

Postby James Bott » Thu Mar 10, 2022 6:36 pm

João,

Perfect master Enrique, this is how I see the VARIABLE STATEMENTS. And so it is written in the CLIPPER 5.3 books and manuals. Perhaps, I have misunderstood something wrong that you wrote. It doesn't matter, you write your programs his way and I write mine. Thank you for the information.

It appears you are missing out on all the advantages of the newer object oriented programming style (OOP). Enrico uses OOP, and variables are not the issue they were in Clipper.

I write almost exclusively in OOP, and the only variable type I normally use is LOCAL. I don't use the type "FIELD" since I only use database objects (e.g. oCustomer:name), and thus no variable type declaration is needed for field names. You can also eliminate PUBLICs using a database object.

I think you are missing out on a lot by not working with OOP. I have taken old programs and reduced the code by more than 50% by converting to OOP.
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Conversion from ca-clipper ( not found a variable)

Postby Marc Venken » Thu Mar 10, 2022 6:44 pm

James,

If you use a Object, and want to see it everywhere, you will use the public/static not ?

I have set is as Static : See my first coding for a solution with having many var in a hash or object. What should I change ?

I'm not sure the "set autorder 1" etc.. from the oMarc are executed



Code: Select all  Expand view  RUN

STATIC oWnd, oDlg, oFont, cClrBack, oBold, oMarc, oGet, oArtChanges

FUNCTION Main()
   LOCAL oFol, oDlg, oRBar, oMenu, oMenuWnd, oBrush1, ;
         oSay1, oBmp, oFont1, oCursor

  // code
   oMarc:= TMarc():new()
   oMarc:aLever = readleveranciers()

   SET AUTORDER TO 1
   SET CENTURY ON
   SET DATE BRITISH
   SET TIME FORMAT TO "HH:MM:SS"
   SET EPOCH TO YEAR( DATE() ) - 30
   SET SOFTSEEK OFF
   SET WRAP ON
   SETCANCEL( .F. )
   SET CONFIRM OFF
   SET DELETED ON
   SET _3DLOOK ON
   SET UNIQUE OFF
   SET ESCAPE OFF
   SET EXACT ON
   SET EXCLUSIVE OFF
   SET MULTIPLE OFF
   SET AUTORDER TO 1
   define font oFontw name "MS Sans Serif" size 0,-50



// more code

   ACTIVATE WINDOW oWnd MAXIMIZED


   oBrush1:End()
   oRBar:End()
   oKlant:End()
   oRec:End()

RETURN NIL

CLASS TMarc
   DATA  aMaanden  AS ARRAY INIT {"Jan","Feb","Mrt"}
   DATA  aDbfVelden  AS ARRAY INIT {}
   DATA  aLever AS ARRAY INIT {}
   DATA  aMerken AS ARRAY INIT readleveranciers("MERKEN")
   //DATA  aLever AS ARRAY INIT readleveranciers()  // Not working
   DATA  aStates AS ARRAY INIT { { } } // state 0 defined as empty
   DATA  name INIT "Just a Name"
   METHOD NEW
ENDCLASS

METHOD NEW CLASS TMarc

   SET AUTORDER TO 1
   SET CENTURY ON
   SET DATE BRITISH
   SET TIME FORMAT TO "HH:MM:SS"
   SET EPOCH TO YEAR( DATE() ) - 30
   SET SOFTSEEK OFF
   SET WRAP ON
   SETCANCEL( .F. )
   SET CONFIRM OFF
   SET DELETED ON
   SET _3DLOOK ON
   SET UNIQUE OFF
   SET ESCAPE OFF
   SET EXACT ON
   SET EXCLUSIVE OFF
   SET MULTIPLE OFF
   SET AUTORDER TO 1
   define font oFontw name "MS Sans Serif" size 0,-50

RETURN SELF

function ReadLeveranciers(cType) //  Steek leverancier, Code en Tag in Array
   local aDbf  := {}
   local c, aDir
   DEFAULT cType := "ALL"
   Minfilesize:= 1
   netopen("Lever")
   //gDBEVAL( { || AAdd( aDbf, FIELD->naam_1 )} )
   do case
      case cType = "ALL"
        DBEVAL( { || AAdd( aDbf, {FIELD->klant_nr,FIELD->naam_1,FIELD->tag} )} )
      case cType = "MERKEN"
        DBEVAL( { || AAdd( aDbf, {FIELD->klant_nr,FIELD->naam_1,FIELD->tag} )} )
   endcase

   //ASORT(aDbf, , , { | x,y | x[2] > y[2] } )  //  Z->A 2 veld
   ASORT(aDbf, , , { | x,y | x[2] < y[2] } )  //  A->Z 2 veld
   close lever

return aDbf

 
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1452
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Conversion from ca-clipper ( not found a variable)

Postby Marc Venken » Thu Mar 10, 2022 7:03 pm

In fact, I would prefer to have a hash for most of my global program data like :

sys_Folder, sys_Date, sys_DocType .... All global settings in 1 hash

function main()

local hDatos := { => } // but this will need to be static or public I think

hDatos["date"] = date()
hDatos["folder"] = "c:\..."
hDatos["type"] = "INVOICE"

then all variables are in a single hdatos variable to pass or call.

So Hash is almost the same as a object..
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1452
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Conversion from ca-clipper ( not found a variable)

Postby James Bott » Thu Mar 10, 2022 7:15 pm

Marc,

If you use a Object, and want to see it everywhere, you will use the public not ?


No, no PUBLICs. There are several ways to eliminate PUBLICS. Here is one:

----------------------------------------------------------
ELIMINATING PUBLICS

Here is a sample showing how you can eliminate publics. One disadvantage of using publics is that they have to be declared in every routine that uses them or you will get compiler warnings. Of course, since they are visible everywhere, you always run the risk of conflicts with locals and fieldnames.

Note that here we are using a static variable oUser (an object). A static variable retains its value as long as the program is running.

Code: Select all  Expand view  RUN
#include "fivewin.ch"

// Class for user
Class TUser
   data name as char
   method new
Endclass

Method new() Class TUser
   ::name:=""
Return self

//------------------------------//

// Create a function. Functions can be called from anywhere in the program.
Function User()
   static oUser
   if oUser == nil
      oUser:= TUser():new()  // instantiate the object
   endif
Return oUser

You can then do this from anywhere:

User():name:= "JBott"        // assign a value

// And call this from anywhere in the program

msgInfo(User():Name, "User Name")       // returns JBott


-----------------
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Conversion from ca-clipper ( not found a variable)

Postby Marc Venken » Thu Mar 10, 2022 10:03 pm

Ok, So my code is in general ok.

oMarc = static

only I have a init clause in the class Tmarc where I define the values, and you define the values in the METHOD NEW CLASS TMarc

I suppose that this a just a choise of the programmer ? or is there a advantage for one option ?

DATA aMaanden AS ARRAY INIT {"Jan","Feb","Mrt"}
DATA aDbfVelden AS ARRAY INIT {}
DATA aLever AS ARRAY INIT {}
DATA aMerken AS ARRAY INIT readleveranciers("MERKEN")
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1452
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

PreviousNext

Return to FiveWin for Harbour/xHarbour

Who is online

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