Is it possible to return a class from a subroutine? If so could I have a small example as it's not as obvious as I thought.
Thanks.
That is a strange question
In general OOP class is a collection of methods or functions or subroutines and as such you can return one of
members of class not class from member....i never tried .
I don't think it's a strange question. A class is just a type just like an integer or string. I have used Java for many years and can return an instance of a class as a return type.
Maybe the use of class has mislead you. I mean an instance of a class, an object.
Look
I am not sure how exactly OOP is created in IWB
and in general i don't like OOP as such
but from your question it looks to me that you want return UDT member-object from
subroutine...
from user guide:
CLASS employee
'methods
DECLARE employee( ) : 'The object constructor
DECLARE _employee( ): 'The object destructor
DECLARE CalculatePay(hours as float),float
DECLARE SetPayRate(amount as float)
DECLARE SetEmployeeID(id as int)
DECLARE PrintPaycheck( )
'members
int m_employeeID
float m_payrate
float m_lastpay
string m_name
pointer m_history
END CLASS
Looks like it's working now. Here you can see createPerson() returns a instance of the person class.
$main
class person
private
string name
public
declare getName(), string
declare setName(string n)
end class
sub person::getName(), string
return name
end sub
sub person::setName(string n)
name = n
end sub
sub createPerson(string name), person
person p1
p1.setName(name)
return p1
end sub
person p1 = createPerson("Aurel")
print p1.getName()
I know that must work ..but as i said ,...i don't use OOP even try to avoid UDT when i can.
good luck ..and read Userguide ;)