Page 1 of 1

Typedef and returns

Posted: Sat Dec 27, 2003 1:32 am
by legider_pb
It would be nice to have typedef AND be able to return said type. For example I create a structure:

Code: Select all

Structure CustomerInfo
    ID.l
    Name.s
    Email.s
EndStructure

TYPEDEF Customer AS CustomerInfo

Procedure.Customer DisplayInfo(Current.Customer)
    Debug Current\ID
    Debug Current\Name
    Debug Current\Email
    
    NewCustomer.Customer
    NewCustomer\ID = 25
    NewCustomer\Name = "Bob"
    NewCustomer\Email = "Bob@Bob.com"

    ProcedureReturn NewCustomer
EndProcedure

Customer1.Customer
Customer1\ID = 15
Customer1\Name = "Frank"
Customer1\Email = "Frank@Frank.com"

Customer2.Customer = DisplayInfo(Customer1)
Well that about sums it up, I know this is possible in a manner of speaking using some API calls and such, but I believe for cross platform things which I am aiming for, this would be immensely useful.

Posted: Sat Dec 27, 2003 4:05 am
by newbie
what's the purpose of that ?
wht not simply as usual write

var.struct ?

I just ask, i don't say it's useless :)

Posted: Sat Dec 27, 2003 9:04 pm
by legider_pb
It's useful because you can define a type that works like a string or a long, but is actually a structure. Which means passing it to functions and returning them from functions easier. It also makes your code easier to organize, maybe this is just my C++ background talking.

Yes in a slight manner of speaking this can be done with pointers, but it is ugly if you ask me