Class syntax not working

Class syntax not working

Postby James Bott » Fri Jun 30, 2017 8:10 pm

Antonio,

I am trying to use the syntaxes, READONLY, HIDDEN, and PROTECTED in classes but none of them are working. I seem to remember that in the past at least some of them were working. The test code below compiles and runs without any errors--and there should be errors. Either the compiler shouldn't allow it, or the running app should report errors. Any ideas?

James

Code: Select all  Expand view
/*
Purpose  : Test OOP syntax: hidden, readonly, protected
Program  :
Author   : James Bott, jbott@compuserve.com
Date     : 06/30/2017 12:58:01 PM
Company  : Intellitech
Language : Fivewin 16.02/xHarbour
Updated  :
Notes    : It seems none of these syntaxes have any affect.

*/


#include "fivewin.ch"

Function Main()
   Local oSyntax
   oSyntax:= TSyntax():new()
   oSyntax:fname := "Mary"
   oSyntax:Lname := "Jones"
   oSyntax:cAlias := "MyAlias"
   
   MsgInfo( oSyntax:fname )
   msgInfo( oSyntax:lname)
   msgInfo( oSyntax:cAlias)
Return nil

Class TSyntax
   Data fname  HIDDEN
   Data lname  PROTECTED
   DATA cAlias READONLY INIT "cAlias"  

   Method New()
endclass

Method New() class TSyntax
   ::fName:="James"
   ::lname:= "Bott"
Return self
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: Class syntax not working

Postby Antonio Linares » Fri Jun 30, 2017 8:54 pm

James,

I never use those clauses.

I hate them since Borland TurboVision times :-) (when I wanted to change some DATAs and it was impossible, forcing you to write extra classes and code)

So I am fraid I can't help you with that
regards, saludos

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

Re: Class syntax not working

Postby Enrico Maria Giordano » Fri Jun 30, 2017 9:31 pm

James, the scope specifiers don't work with xHarbour but work with Harbour:

Code: Select all  Expand view
Error BASE/41  Scope violation (hidden): TSYNTAX:_FNAME
Error BASE/42  Scope violation (protected): TSYNTAX:_LNAME
Error BASE/42  Scope violation (protected): TSYNTAX:_CALIAS


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

Re: Class syntax not working

Postby James Bott » Fri Jun 30, 2017 10:07 pm

Antonio,

I hate them since Borland TurboVision times (when I wanted to change some DATAs and it was impossible, forcing you to write extra classes and code)


OK, I get that. In my case I am just trying to protect myself from me! It's hard to remember what can be changed without unintended consequences, and what can be changed. Since, I have the source, I can change my mind about the level of protection at a later time.

Enrico,

So you are saying it is a xHarbour issue? I assume the output you posted was from a Harbour compile?

Thanks for the responses, both of you.

James
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: Class syntax not working

Postby Enrico Maria Giordano » Fri Jun 30, 2017 10:18 pm

James Bott wrote:Enrico,

So you are saying it is a xHarbour issue? I assume the output you posted was from a Harbour compile?


Yes. But this is from xdiff.txt:

Module Scope:
-------------

OOP Scoping supports PRIVATE/HIDDEN, PROTECTED, and READONLY scopes. Classes
sharing the SAME compilation unit may freely access such restricted access
Members, without causing any scope violation.


So, I assume (not tested) that the scope specifiers would work in xHarbour too outside the same PRG.

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

Re: Class syntax not working

Postby James Bott » Fri Jun 30, 2017 10:47 pm

Well, I should have done this first. I dug through all my notes and I found the note below from 2006. This explains a lot.

This does make it difficult to write code that works with both xHarbour and Harbour.

Of course, things may well have changed since then so I still need to do some testing.

James

OK, after a considerable amount of work I finally have xHarbour up and running. I ran some class scoping tests and this is what I found.

FW/Clipper
HIDDEN Only visible within the class in which it is defined and it's subclasses.
PROTECTED Visible everywhere. Not assignable outside the class or subclass.
READONLY Same as protected.

FWH/Harbour
All class scope syntax is ignored and everything is treated as EXPORTED.

FWH/xHarbour
Note that these don't work when the class is in the same prg as the code.
HIDDEN Only visible within the class in which it is defined. Not visible in subclasses.
PROTECTED Only visible within the class in which it is defined and it's subclasses.
READONLY Visible everywhere. Not assignable outside the class or subclass.

In summary, HIDDEN in FW/Clipper is the same as PROTECTED in FWH/xHarbour. PROTECTED and READONLY are synonymous in FW/Clipper, but have different scopes in FWH/xHarbour.
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: Class syntax not working

Postby nageswaragunupudi » Sat Jul 01, 2017 8:23 pm

So, I assume (not tested) that the scope specifiers would work in xHarbour too outside the same PRG.

Yes.
If we keep the class alone in a different module, then both xHarbour and Harbour work alike.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 128 guests