FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Instance var with READONLY attribute
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Instance var with READONLY attribute
Posted: 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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Instance var with READONLY attribute
Posted: Fri Dec 01, 2006 08:31 AM

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

EMG

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Instance var with READONLY attribute
Posted: Fri Dec 01, 2006 09: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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Instance var with READONLY attribute
Posted: Fri Dec 01, 2006 09: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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Instance var with READONLY attribute
Posted: Fri Dec 01, 2006 08: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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion