Instance var with READONLY attribute

Instance var with READONLY attribute

Postby James Bott » Thu Nov 30, 2006 10:05 pm

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
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Instance var with READONLY attribute

Postby Enrico Maria Giordano » Fri Dec 01, 2006 8:31 am

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

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

Postby James Bott » Fri Dec 01, 2006 9:11 am

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
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Postby Enrico Maria Giordano » Fri Dec 01, 2006 9:22 am

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

Postby James Bott » Fri Dec 01, 2006 8:32 pm

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
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: No registered users and 59 guests