Happy new year everyone.
Kindly review this code;
[quote]
#include 'minigui.ch'
#include 'hbclass.ch'
msgInfo(valType(tCash():new())) // returns O
msgInfo(valType(tCash():init())) // returns U
*----------------
* tCash Class def
*----------------
CREATE CLASS tCash
EXPORT:
METHOD init()
ENDCLASS
METHOD init()
return NIL
* End of tCash class def
*------
[/quote
Is this an intended behaviour?
Harbour classes: Init() vs new() method
Moderator: Rathinagiri
- karweru
- Posts: 220
- Joined: Fri Aug 01, 2008 1:51 pm
- DBs Used: DBF,mysql,mariadb,postgresql,sqlite,odbc
- Contact:
Harbour classes: Init() vs new() method
Kind regards,
Gilbert.
Gilbert.
Re: Harbour classes: Init() vs new() method
karweru wrote:Is this an intended behaviour?
METHOD init()
return NIL
* End of tCash class def
*------
You use return NIL... try RETURN 1, or RETURN .F.
If you want to return the object, use RETURN Self
- karweru
- Posts: 220
- Joined: Fri Aug 01, 2008 1:51 pm
- DBs Used: DBF,mysql,mariadb,postgresql,sqlite,odbc
- Contact:
Re: Harbour classes: Init() vs new() method
Hi Mrduck,mrduck wrote:karweru wrote:Is this an intended behaviour?
METHOD init()
return NIL
* End of tCash class def
*------
You use return NIL... try RETURN 1, or RETURN .F.
If you want to return the object, use RETURN Self
Nil is returned intentionally. My question was why the new() & init() methods return different values, and whether this is intentional or a bug?
Kind regards,
Gilbert.
Gilbert.
Re: Harbour classes: Init() vs new() method
This is the answer to your question. You returned NIL and valtype(NIL) is "U"karweru wrote: Nil is returned intentionally.
Method init() is defined in the class so it is used the method in the class.
New() is not defined in the class... all classes defined in harbour code "secretely" inherit from a base class that provides basic methods (like className).. one of these methods is New() that (I havent' seen the code, I just imagine) is just
METHOD NEW
RETURN Self
Is it clear now ?
- karweru
- Posts: 220
- Joined: Fri Aug 01, 2008 1:51 pm
- DBs Used: DBF,mysql,mariadb,postgresql,sqlite,odbc
- Contact:
Re: Harbour classes: Init() vs new() method
Crystal clear, thanks. I had all along assumed the new() method always called init() method internally.mrduck wrote: Is it clear now ?
Thanks.
Kind regards,
Gilbert.
Gilbert.