FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Class syntax not working
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Class syntax not working
Posted: Fri Jun 30, 2017 08: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 (fw): Select all Collapse
/*
Purpose  : Test OOP syntax: hidden, readonly, protected
Program  : 
Author   : James Bott, <!-- e --><a href="mailto:jbott@compuserve.com">jbott@compuserve.com</a><!-- e -->
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
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Class syntax not working
Posted: Fri Jun 30, 2017 08: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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Class syntax not working
Posted: Fri Jun 30, 2017 09:31 PM
James, the scope specifiers don't work with xHarbour but work with Harbour:

Code (fw): Select all Collapse
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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Class syntax not working
Posted: 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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Class syntax not working
Posted: 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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Class syntax not working
Posted: 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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Class syntax not working
Posted: Sat Jul 01, 2017 08: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

Continue the discussion