FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour xHarbour class designations Protected and Hidden not working
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
xHarbour class designations Protected and Hidden not working
Posted: Wed May 01, 2013 02: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 (fw): Select all Collapse
/*
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 (fw): Select all Collapse
#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
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: xHarbour class designations Protected and Hidden not working
Posted: Wed May 01, 2013 03:30 PM
James,

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

Code (fw): Select all Collapse
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL oWnd := TWindow():New()

    ? oWnd:nHorzRes()

    ? oWnd:SetAlphaLevel()

    RETURN NIL


EMG
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: xHarbour class designations Protected and Hidden not working
Posted: Wed May 01, 2013 04: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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: xHarbour class designations Protected and Hidden not working
Posted: Wed May 01, 2013 07: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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: xHarbour class designations Protected and Hidden not working
Posted: Wed May 01, 2013 08:34 PM

Thanks for the clarification Rao.

James

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: xHarbour class designations Protected and Hidden not working
Posted: Wed May 01, 2013 08: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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: xHarbour class designations Protected and Hidden not working
Posted: 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

Continue the discussion