FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour syntax on a class
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
syntax on a class
Posted: Wed Apr 27, 2016 02:43 PM
I with create a method if I have a logic value .t.

METHOD SetUpperCaps(lUpp) INLINE if(lUpp, ::func1(),::func2())


or
how I must make it ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: syntax on a class
Posted: Wed Apr 27, 2016 05:47 PM
Silvio,

Normally you would do something like this:

Code (fw): Select all Collapse
Method SetUpper( lUpper )
   if lUpper != nil
      ::lUpper:= lUpper
   endif
return ::lUpper

Method Whatever( cString )
   if ::lUpper
       cString:= upper( cString )
   endif
return cString


Note that you could just access ::lUpper directly like oObj:=.t. without the setUpper() method, but OOP principles state that no DATA should be accessed directly, but rather should be set using a method. This does prevent data from being changed that may depend on other settings (DATA) being set a particular way, and visa versa. I think this is a bigger concern when you have multiple programmers working on a project that might not be fully aware of the consequences of changing DATA directly.

However, your definition could work. Did you try it? However, if you need to pass something to either func1() or func2() then they would have to be passed to the setUpper() method which is very confusing. It is better to set the DATA (::lUpper) then use that data in a method that does different things depending on its value (such as my Whatever() method).

James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: syntax on a class
Posted: Thu Apr 28, 2016 08:00 AM

resolve
xhabour not want !lUpp on comand inline

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com

Continue the discussion