xHarbour class designations Protected and Hidden not working

xHarbour class designations Protected and Hidden not working

Postby James Bott » Wed May 01, 2013 2:33 pm

I just noticed that the class designations "Protected" and "Hidden" are not working in xHarbour 1.2.1. Both Protected and Hidden vars ARE visible outside the class and they should not be. Below is a simple test program. Can anyone test this under the latest xHarbour for me? Both msgInfo()'s should error out. I note that the preprocessor shows them with different scopes, but they are still visible.

Regards,
James

Test program:

Code: Select all  Expand view
/*
Purpose : Test protected and hidden variables in a class
Notes   : Neither protected nor hidden vars should be visible outside the class
Compiler: xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6717)
Author  : James Bott
Date    : 5/1/2013
*/


#include "fivewin.ch"

function main()
   local oTest

   oTest:= TTest():new()

   msgInfo( oTest:cProtectedText,"This should not be visible:" )

   msgInfo( oTest:cHiddenText,"This should not be visible:" )

return nil

class TTest

   exported:
   method new()

   protected:
   data cProtectedText

   hidden:
   data cHiddenText

endclass

method new()
   ::cProtectedText:="Protected text"
   ::cHiddenText:= "Hidden text"
return self
 


Preprossor output:

Code: Select all  Expand view
#line 112 "hbclass.ch"
   DYNAMIC DivertConstructorCall

DECLARE HBClass  New( cName AS String, OPTIONAL SuperParams ) AS CLASS HBClass  Create() AS Object  Instance() AS Object  AddClsMethod( cName AS String, @MethodName(), nScope AS Numeric, n2 AS Numeric, n3 AS Numeric )  AddDelegate( cName AS String, cDelegate AS String, cObject AS String, nScope AS Numeric, lPersistent AS LOGICAL )  AddMultiClsData( cType AS String, uVal, nScope AS Numeric, aDatas AS Array OF String )  AddMultiData( cType AS String, uVal, nScope AS Numeric, aDatas AS Array OF String, x AS LOGICAL, lPer AS LOGICAL )  AddMethod( cName AS String, @MethodName(), nScope AS Numeric, lPersistent AS LOGICAL )  AddInLine( cName AS String, bBlock AS CodeBlock, nScope AS Numeric, lPersistent AS LOGICAL )  AddVirtual( cName AS String )  ModMethod( cName AS String, @MethodName(), nScope AS Numeric, lPersistent AS LOGICAL )  ModClsMethod( cName AS String, @MethodName(), nScope AS Numeric )  ModInline( cName AS String, bBlock AS CodeBlock, nScope AS Numeric, lPersistent AS LOGICAL )  SetOnError( @MethodName() )
#line 86 "c:\fwh\include\fivewin.ch"
   EXTERNAL GetProcAdd
   EXTERNAL TActiveX

extern errorsys
#line 11 "TTest.prg"
function main()
   local oTest

   oTest:= TTest():new()

   msgInfo( oTest:cProtectedText,"This should not be visible:" )

   msgInfo( oTest:cHiddenText,"This should not be visible:" )

return nil

_HB_CLASS TTest ; UTILITY FUNCTION TTest(...); static s_oClass ; local oClassInstance ; local nScope ; nScope := 1 ; if s_oClass == NIL ; s_oClass := IIF(.F.,, HBClass():New( "TTest" , { HBObject():Classh } ) ) ;

   nScope := 1
   _HB_MEMBER new(); IIF( .F., s_oClass:ModMethod( "new", @TTest_new(), nScope + IIF( .F., 16, 0 ) + IIF( .F., 1024, 0 ), .F. ), s_oClass:AddMethod( "new", @TTest_new(), nScope + IIF( .F., 16, 0 ) + IIF( .F., 1024, 0 ), .F. ));

   nScope := 4
   _HB_MEMBER { cProtectedText} ; IIF( !.F., s_oClass:AddMultiData(,, nScope + IIF( .F., 32, 0 ), { "cProtectedText" }, .F., .F. ), )

   nScope := 8
   _HB_MEMBER { cHiddenText} ; IIF( !.F., s_oClass:AddMultiData(,, nScope + IIF( .F., 32, 0 ), { "cHiddenText" }, .F., .F. ), )

; IF .F. ; __clsActive(s_oClass:hClass) ; s_oClass:Refresh() ; ELSE ; s_oClass:Create() ; END ; oClassInstance := __clsInst( s_oClass:hClass ) ; IF __ObjHasMsg( oClassInstance, "InitClass" ); oClassInstance:InitClass( hb_aParams() ) ; END ; ELSE ; oClassInstance := __clsInst( s_oClass:hClass ) ; END ; IF PCount() > 0 ; DIVERT TO (@DivertConstructorCall()) OF s_oClass ; END ; RETURN oClassInstance AS CLASS TTest ;

UTILITY STATIC function TTest_new() ; local Self AS CLASS TTest := QSelf() AS CLASS TTest
   ::cProtectedText:="Protected text"
   ::cHiddenText:= "Hidden text"
return self
 
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: xHarbour class designations Protected and Hidden not working

Postby Enrico Maria Giordano » Wed May 01, 2013 3:30 pm

James,

the class definition must be in a different PRG for PROTECTED and HIDDEN to work:

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oWnd := TWindow():New()

    ? oWnd:nHorzRes()

    ? oWnd:SetAlphaLevel()

    RETURN NIL


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

Re: xHarbour class designations Protected and Hidden not working

Postby James Bott » Wed May 01, 2013 4:02 pm

Enrico,

Well that explains a lot. Normally, I do have my classes in a separate PRG, but I was just doing some testing when I discovered I could access the hidden vars.

Thanks, I wouldn't have thought of that.

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

Re: xHarbour class designations Protected and Hidden not working

Postby nageswaragunupudi » Wed May 01, 2013 7:29 pm

In xHarbour protected and hidden data are visible in other classes/functions in the same module. That is something we do not expect but it is so. I do not know if this is a bug or intentional design.

But in Harbour they are not visible outside the class, even in the same module.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: xHarbour class designations Protected and Hidden not working

Postby James Bott » Wed May 01, 2013 8:34 pm

Thanks for the clarification Rao.

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

Re: xHarbour class designations Protected and Hidden not working

Postby cnavarro » Wed May 01, 2013 8:48 pm

nageswaragunupudi wrote:In xHarbour protected and hidden data are visible in other classes/functions in the same module. That is something we do not expect but it is so. I do not know if this is a bug or intentional design.

But in Harbour they are not visible outside the class, even in the same module.


And in class we created "inherited" from them?
You can create methods type SET / GET to use?
regards
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: xHarbour class designations Protected and Hidden not working

Postby nageswaragunupudi » Wed May 01, 2013 10:46 pm

And in class we created "inherited" from them?
You can create methods type SET / GET to use?

Yes. Inherited classes see protected as it should be.
In case of xHarbour they can see hidden also if they are in the same module.
But it is not a good practice to use them.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10632
Joined: Sun Nov 19, 2006 5:22 am
Location: India


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Antonio Linares and 87 guests