PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: How to return the real data from a udt ?  (Read 540 times)

Vinod Chandran

  • FireFly3 User
  • Little Newbie FireFly
  • *
  • Posts: 5
How to return the real data from a udt ?
« on: April 19, 2018, 05:04:10 PM »

Hi Jose Roca,
Code: [Select]
Dim sample As CWSTR = "My Sample String"
Print sample
This will print "My Sample String" on screen. I know that cwstr is a udt. What is the magic behind this ? I mean when i try to write a udt like this
Code: [Select]
Type MyType
m_String As String
Declare Constructor(Byval sParam As String)

End Type
Constructor MyType(Byval sParam As String)
m_String = sParam
End Constructor
 
Dim sample As MyType = "enter man"
Print sample
It result in an "Invalid data type " error. I know that i am missing so many things in my constructor. I have posted this code only for expressing my idea because, i knew that i cant really express this idea through words. English is not my first language. Thats why the subject title look weird. Could you please explain me how to do this ?
Logged

Vinod Chandran

  • FireFly3 User
  • Little Newbie FireFly
  • *
  • Posts: 5
Re: How to return the real data from a udt ?
« Reply #1 on: April 19, 2018, 05:10:02 PM »

Hi,
I am i missing this ?
Code: [Select]
Declare Operator Print(Byval udtName as MyType)And ...
Code: [Select]
Operator MyType.Print(Byval udtName as MyType)
    Print udtName. m_String
End Operator
Logged

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3109
    • Jos
Re: How to return the real data from a udt ?
« Reply #2 on: April 19, 2018, 05:14:19 PM »

The "magic" is casting.

Code: [Select]
Type MyType
m_String As String
Declare Constructor(Byval sParam As String)
DECLARE OPERATOR CAST () BYREF AS STRING
End Type
Constructor MyType(Byval sParam As String)
m_String = sParam
End Constructor

OPERATOR MyType.CAST () BYREF AS STRING
   OPERATOR = m_String
END OPERATOR

Dim sample As MyType = "enter man"
Print sample

Vinod Chandran

  • FireFly3 User
  • Little Newbie FireFly
  • *
  • Posts: 5
Re: How to return the real data from a udt ?
« Reply #3 on: April 28, 2018, 08:51:33 AM »

@Jose,
Wow!, Thanks a lot.
Logged