Instance var with READONLY attribute

Post Reply
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Instance var with READONLY attribute

Post by James Bott »

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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Re: Instance var with READONLY attribute

Post by Enrico Maria Giordano »

As I already answered on xHarbour newsgroup, the access modifiers have no effect at the module level.

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

Post by James Bott »

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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

Post by Enrico Maria Giordano »

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?
Exactly.
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
From the xHarbour newsgroup:
"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
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Post by James Bott »

Thanks Enrico. How very strange that I cannot see either my message or your reply in the xHarbour newsgroup. I just checked it again this morning and I still can't see it. I do have 4 blocked senders for newsgroups but neither you or I are among them. I have never had this happen before.

James
Post Reply