Class DATA getSet

Issues and Discussions related to Harbour

Moderator: Rathinagiri

Post Reply
User avatar
karweru
Posts: 220
Joined: Fri Aug 01, 2008 1:51 pm
DBs Used: DBF,mysql,mariadb,postgresql,sqlite,odbc
Contact:

Class DATA getSet

Post by karweru »

Hi Friends,

I want to illustrate my question with the code below;

Code: Select all


CREATE CLASS student
DATA name
DATA age
EXPORT:
METHOD name(cName) INLINE ::getSet("name",cName)
METHOD age(nAge) INLINE ::getSet("age",nAge)
METHOD getSet(xVar,xVal)
ENDCLASS

METHOD init()
::name:=""
::age=:=0
RETURN self

METHOD getSet(xVar,xName)
nPars:=pCount()
do case 

case (xVar:=upper(xVar))=="NAME"
 if nPars==2
::name:=xVal
endif
return ::name

case xvar=="AGE"
if nPars==2
::age:=xVal
endif
return ::age
endcase
return Nil
My question is about the getset() method manner of coding. Is there a function that can be used to get/set DATA in a class. I stumbled on classSel() which can list all the DATA in the class but is there a function(s) that can be used so that the getSet() method above can be coded as below;

getDataFunction(<xVar>)

setDataFunction(<xVar>,<xVal>)

Thank you in advance.
Kind regards,
Gilbert.
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Class DATA getSet

Post by esgici »

karweru wrote:...
My question is about the getset() method manner of coding. Is there a function that can be used to get/set DATA in a class.
Hi Gilbert

Frankly, I'm not an OOP expert.

Recently past a thread in Harbour users forum, including a document on Harbour OOP.

I hope it may be useful.

Happy HMG'ing :D
Viva INTERNATIONAL HMG :D
User avatar
karweru
Posts: 220
Joined: Fri Aug 01, 2008 1:51 pm
DBs Used: DBF,mysql,mariadb,postgresql,sqlite,odbc
Contact:

Re: Class DATA getSet

Post by karweru »

Hi Esgici,

Thank you very much for your interest in this subject...I was able to resolve the question and consequently used this style to re-write HMGobjects, very compressed/shortened verson, for use in my projects.
The solution was using macros as below, (using the same code above for illustration);

Code: Select all

CREATE CLASS student
DATA name
DATA age
EXPORT:
METHOD name(cName) INLINE ::getSet("name",cName)
METHOD age(nAge) INLINE ::getSet("age",nAge)
METHOD getSet(xVar,xVal)
ENDCLASS

METHOD init()
::name:=""
::age=:=0
RETURN self

METHOD getSet(xVar,xName)
local get_Var,set_Var

get_var:="qself():_"+xVar
set_var:="qself():"+xVar

if valType(xVal)!="U"
&set_Var:=xVal
endif
return &get_Var

Thank you again Esgici.
Kind regards,
Gilbert.
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Class DATA getSet

Post by esgici »

Hi Gilbert

I was should interested; because your question left 20 days unanswered;

and I know well what is being left unanswered, waiting unresponsive :(

I'm glad that you have found yourself an answer to your question.

And thanks to share your code with us :)

Happy HMG'ing :D
Viva INTERNATIONAL HMG :D
User avatar
dhaine_adp
Posts: 457
Joined: Wed Aug 06, 2008 12:22 pm
Location: Manila, Philippines

Re: Class DATA getSet

Post by dhaine_adp »

Hi Gilbert,

Here's a shortened version of your solution without the local variables on method getSet():

Code: Select all

CREATE CLASS student
   DATA name INIT NIL HIDDEN
   DATA age  INIT  0 HIDDEN

   EXPORT:
   METHOD New() CONSTRUCTOR
   METHOD name(cName) INLINE ::getSet("name",cName)
   METHOD age(nAge) INLINE ::getSet("age",nAge)
   METHOD getSet(xVar,xVal)
ENDCLASS

METHOD New()
   RETURN self

METHOD getSet( cPropName, xVal )

   IF PCOUNT() == 1
      return ::&( cPropName )
   ELSE
      ::&( cPropName ) := xVal
   ENDIF
   RETURN Self
Regards,

Danny
Manila, Philippines
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Class DATA getSet

Post by Rathinagiri »

Interesting!
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
Post Reply