RELEASE ALL LIKE Does not work !!!

RELEASE ALL LIKE Does not work !!!

Postby vilian » Wed Jan 20, 2010 5:55 pm

When I run the program below I have different results depending on the version I use xHarbour

With xHarbour 1.1.0 appears NULL in two commands " ? cVar " .
With xHarbour 1.2.1 a NULL is displayed and then 10. The RELEASE ALL did not erase the contents of the variable!

Code: Select all  Expand view

#include "FiveWin.ch"

FUNCTION Main()
PRIVATE cVar

   ? cVar
   cVar := 10

   RELEASE ALL LIKE cVar*

   ? cVar

RETURN nil
 
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 975
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: RELEASE ALL LIKE Does not work !!!

Postby James Bott » Wed Jan 20, 2010 7:36 pm

Vilian,

I know this doesn't answer your problem, but I recommend never using privates. They generate bugs that are nightmares to find. I haven't used a private in more than 10 years.

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: RELEASE ALL LIKE Does not work !!!

Postby Antonio Linares » Wed Jan 20, 2010 8:40 pm

Vilian,

It seems as a xHarbour bug that should be reported in the xHarbour developers (and/or users) list, thanks
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: RELEASE ALL LIKE Does not work !!!

Postby vilian » Thu Jan 21, 2010 12:16 pm

Antonio,

In harbour is ok ?
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 975
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: RELEASE ALL LIKE Does not work !!!

Postby AlexSchaft » Fri Jan 22, 2010 7:12 am

It's still an xharbour bug that has nothing to do with fivewin
User avatar
AlexSchaft
 
Posts: 172
Joined: Fri Oct 07, 2005 1:29 pm
Location: Edenvale, Gauteng, South Africa

Re: RELEASE ALL LIKE Does not work !!!

Postby Antonio Linares » Fri Jan 22, 2010 9:01 am

Vilian,

In Harbour is also seems to fail.

Enrico, could you please test it too ? Thanks
We may need to report it to the Harbour mailing list too.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: RELEASE ALL LIKE Does not work !!!

Postby Enrico Maria Giordano » Fri Jan 22, 2010 11:12 pm

Problem confirmed and already reported to Harbour and xHarbour developers.

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

Re: RELEASE ALL LIKE Does not work !!!

Postby Antonio Linares » Sat Jan 23, 2010 9:49 am

Enrico,

Thanks! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Re: RELEASE ALL LIKE Does not work !!!

Postby driessen » Sun Jan 24, 2010 1:07 pm

James,

What do you use in stead of private variables ?

I use them a lot, and I never experienced any problem.

Thanks.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: RELEASE ALL LIKE Does not work !!!

Postby Enrico Maria Giordano » Sun Jan 24, 2010 1:20 pm

The only problem of PRIVATE and PUBLIC variables is their non-local scope. If you really need of a variable with non-local scope then you should first look at filewide STATIC variables.

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

Re: RELEASE ALL LIKE Does not work !!!

Postby James Bott » Wed Jan 27, 2010 5:49 pm

Michel,

>What do you use instead of private variables ?

The worst problems come from code where variables are undeclared as was the typical practice with Clipper. Here is an example.

Code: Select all  Expand view
function main()
   use invoice  // contains field named "TOTAL"
   dowhatever()
return nil


function dowhatever()
   total:= 10
   msgInfo(total,"total")  // returns 7.00
return nil

Total in the above routine is returning the value in the fieldname TOTAL not the private named total. This is very confusing.

In this example we declare the variable as a LOCAL.

Code: Select all  Expand view
function dowhatever()
   LOCAL total
   total:= 10
   msgInfo(total,"total")  // returns 10.00
return nil


Now total returns the expected amount.

There is almost always an open file in the current workarea so there is a constant risk the fieldnames will override privates. If you add a field to a file, it could end up breaking your code. Conversely, you could add a PRIVATE that could end up breaking your code. These kinds of bugs are very hard to find since they may only occur under certain circumstances (when a certain file is open and in the current workarea).

My solution? I program extensively using OOP. My apps are also classes.

Code: Select all  Expand view
class TApp
   data ...
   method New()
   method Activate()
   ...
endclass


Then all you need to run your app is:

Code: Select all  Expand view
function Main()
   TApp():new():activate()
return nil


So anywhere in the app I can refer to data of the class.

And I create business classes, like customer, item, invoice, etc. Within these classes I have all the needed code related to the real-world item. This includes all the data as class data so no privates are needed.

I also use LOCALs and declare all variables. I compile with the \w parameter to ensure that all variables are declared.

You can also eliminate publics. The App class handles some requirements and you can use a set/get function to store any variable you need. A set/get function stores the data as a STATIC.

Set the path.

path( cPath )

Get the path anywhere in your code.

cPath := path()

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: RELEASE ALL LIKE Does not work !!!

Postby Enrico Maria Giordano » Wed Jan 27, 2010 6:03 pm

James Bott wrote:The worst problems come from code where variables are undeclared as was the typical practice with Clipper.


This problem completely vanishes if you use /w compiler switch and proper declare the variables (what I always do):

Code: Select all  Expand view
PRIVATE test
...

M -> test


The non-local scope problem still stands, though.

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

Re: RELEASE ALL LIKE Does not work !!!

Postby James Bott » Wed Jan 27, 2010 6:13 pm

Enrico,

>This problem completely vanishes if you use /w compiler switch and proper declare the variables (what I always do):

Yes. I did mention the problem was with undeclared variables (and I have seen lots of applications without a single declared variable).

Still, as you stated, privates are visible everywhere (even within FW and Harbour code) as long as they are in scope. So you have to worry about naming conflicts in all your code, even code that is unrelated to the Privates.

I just don't see any good reason to use Privates. I think they are only still available for backwards compatibility. There was a time when Clipper did not have LOCALs, STATICs, and OOP capability. Then PRIVATEs were needed. Not anymore.

Regards,
James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA


Return to FiveWin for Harbour/xHarbour

Who is online

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