Results 1 to 2 of 2

Thread: Allow Me without dot or Extends <PrimitiveType>

  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171

    Allow Me without dot or Extends <PrimitiveType>

    Once more I'm in the need of something like this:

    for <primitive> insert any of these:
    Byte, Word, Integer, Boolean, DWord, Long, Single, Double, Extended, Ext [, String [ * Size]]

    ' currently:
    Type tType
      myVal As <primitive>    
      
      Static whatever As Number
    
      Function _Create(Byval myVal As <primitive>)
        Me.myVal = myVal
      End Function
    ' this Type now only has 1 Subelement of Type <primitive>
    ' SizeOf(tType) equals SizeOf(<primitive>) 
    ' omit something that follows below here...
    End Type
    
    Dim X As tType(123)
    

    now there are 2 ways for a solution:

    the simple one:

    Me or the variablename of tType to use without . (dot, followed by { Static-name | Function-Name})
    should refer to the first udt-subelement (thats Varptr equals the pointer to the variable itself of course...)
    so it would be valid to use X as well as X.myVal in the example above

    more complicated:
    Type tType Extends <primitive>
    
      Static whatever As Number
      
      Function _Create(Byval myVal As <primitive>)
        Me = myVal
       ' Me gets treated like <primitive>
      End Function
    
      Function GetVal() As <primitive>
        Function = Me
      End Function
      
      Function SetVal(Byval myVal As <Primitive>) As <primitive>
        Me = myVal
        Function = Me
      End Function
      
      Function AddVal(Byval myVal As <Primitive>) As <primitive>
       ' If <Primitive> = STRING * SIZE Then
      ' --- would work different (add up all bytes values perhaps???)
       ' Else
          Me += myVal
       ' Endif
        Function = Me
      End Function
    End Type
    
    Dim X As tType(123)  ' almost equals: Dim X As <primitive> Value 123
    
    ' the difference is that X as tType is able to have functions & statics, so one can use for example:
    ' X gets treated like <primitive>
    X = 123
    ' should equal
    X.SetVal(123)
    
    X += 123
    ' equals then
    X.AddVal(123)
    
    PrintL X 
                ' should equal the output for
    PrintL X.GetVal()
    

    It is not allowed to have any other UDT-subelements butStatic's and Function's when Extends <primitive>.
    Assigning and getting the value works like if it were a normal variable of type <primitive>.

    If another Type extends the extended <primitive>, the use of only Me or the variables name without
    . (dot) followed by { Static-name | Function-Name} should still work like it were a variable of <primitive>.
    Last edited by ReneMiner; 08-11-2015 at 14:42.
    I think there are missing some Forum-sections as beta-testing and support

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,782
    Rep Power
    10
    Ciao René,

    I think your idea is too much advanced for the OOP level thinBasic actually is.
    We need to make a lot of intermediate steps before being able to develop something like the one you suggested that in OOP is called something like Generics: https://msdn.microsoft.com/en-us/lib...(v=vs.80).aspx

    Actually I'm working on the possibility to add any data type (static and dynamic) inside TYPEs.
    I think if I will succeed on this, a lot of new possibilities will be discovered.

    Sorry but I cannot see any way to develop your request at the moment.

    Ciao
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

Similar Threads

  1. union-extends-bug?
    By ReneMiner in forum Core module
    Replies: 0
    Last Post: 04-10-2014, 14:02

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •