Perhaps this is a xHarbour question, but if I create an instance variable with the READONLY attribute, shouldn't it be protected from having an assignment. xHarbour is allowing me to assign data directly to a READONLY variable. I think it should be generating an error.
I am using the Sept 2006 version of FWH/xHarbour.
James
#include "fivewin.ch"
function main()
local oObj:= TTest():new()
oObj:cVar := "Test readonly"
msgInfo( oObj:cVar ) // returns "Test readonly"
return nil
class TTest
data cVar READONLY
method new()
endclass
method new() class TTest
return self
// eof
Instance var with READONLY attribute
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Instance var with READONLY attribute
As I already answered on xHarbour newsgroup, the access modifiers have no effect at the module level.
EMG
EMG
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Enrico,
>As I already answered on xHarbour newsgroup, the access modifiers have no effect at the module level.
I'm sorry I'm not sure what you are saying. Do you mean if the program and the class are in the same PRG?
Did you answer my question on the xHarbour newsgroup? I tried to post the same question there, but it never showed up. I still don't see it.
James
>As I already answered on xHarbour newsgroup, the access modifiers have no effect at the module level.
I'm sorry I'm not sure what you are saying. Do you mean if the program and the class are in the same PRG?
Did you answer my question on the xHarbour newsgroup? I tried to post the same question there, but it never showed up. I still don't see it.
James
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Exactly.James Bott wrote:Enrico,
>As I already answered on xHarbour newsgroup, the access modifiers have no effect at the module level.
I'm sorry I'm not sure what you are saying. Do you mean if the program and the class are in the same PRG?
From the xHarbour newsgroup:James Bott wrote:Did you answer my question on the xHarbour newsgroup? I tried to post the same question there, but it never showed up. I still don't see it.
James
"James Bott" <jbottREMOVE@compuserve.com> ha scritto nel messaggio
news:456f5998@bekz-be....
>
> I do believe that if an instance variable is marked as READONLY then you
> should not be able to assign a value to it outside the class. But you
> can--no error is generated.
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.
EMG
--
EMAG Software Homepage: http://www.emagsoftware.it
The EMG's ZX-Spectrum Page: http://www.emagsoftware.it/spectrum
The Best of Spectrum Games: http://www.emagsoftware.it/tbosg
The EMG Music page: http://www.emagsoftware.it/emgmusic
EMG
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact: