Results 1 to 1 of 1

Thread: Type ... As ... ?

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

    Type ... As ... ?

    Spooking through my head for a long time already, the thought how to have functional standard/primitive variables (Long, Dword etc.) without having an additional ".Subelementname" to add- means to be able to use them as the standard-type.

    Think of
    Alias Dword As SpecialDword
    
    that would NOT make the "specialized Dword" functional now nor would it be possible to
     Dim chi Like "SpecialDword" '- Error.
    
    but would keep it's compatibility with any Dword, so can be treated as a Dword. (pass byref, peek, array scan etc.)

    Now if I do this:
    Type tSpecialDword
      myVal As Dword
      myFun As Function
      Static myStat As Boolean
    End Type
    
    Function tSpecialDword.myFun() As Dword
    ' here it's Me.myVal that contains the DWord
      Function = Me.myVal
    End Function
    
    Dim chi as tSpecialDword 
    chi.myVal = 123
    
    I would have the specialized Dword that's real content is to find at chi.myVal and that were able to have as well Statics and Functions, maybe Const in future too.
    But to read the value from the variable chi one would always have to append .myVal and this makes it impossible to use chi as a standard-Dword, what if chi were an array or subelement of another UDT here? It would become complicated...but we know Varptr(chi) equals Varptr(chi.myVal) and both means the same...

    We could make all those ID's and handles that we have currently become functional - and also enable them to keep global track about their members & append their specific constants into their hability-zone instead of having them global because they would have the opportunity of statics/constants inside the appended UDT.

    It would mean a special kind of udt that only consists of one standard-variable(Byte, Long, Dword etc.)

    perhaps you'll understand better if read this syntax
    Uses "console"      
    
    Type tSpecialDword Extends DWord  ' this gives an Error - missing As-clause
    '...not to mention simply putting "DWord" onto an empty line here...
      myFun         As Function
      Static myStat As Boolean
    End Type
    
    Function tSpecialDword.myFun() As DWord
    
      Function = Me
    
    End Function
    
    Dim chi As tSpecialDword ' = 123 ... instant assignement ...hm ok...
    'in reality we would use a init-, load- or setup-function here mostly.
    chi = 123
    
    PrintL Str$(chi.myFun)  ' should print 123
    WaitKey
    
    or

    Type tSoundChannel As DWord  ' this gives an Error too
    
    ' means: this UDT will consist of one Dword-Variable only.
    ' there can be statics & functions [+const] but no other subelements
      Static globalVolume As Long
      Play         As Function
    '...
    End Type
    
    I want to have "Me" as well as the variable-name to be treateable as a standard-type (Long & Dword mostly) without the requirement of a ".Subelementname" so either
    "Type x Extends Dword" as well as "Type x As Dword"

    could be an option in order to have functional handles, ID's, resource-slots, specialized variables etc.
    As mentioned, their Static-properties were very nice place for type/unit/module-specific values, constants and global common values & settings that go to all of this specific type but is not of interest to any other parts of the application.

    +++

    Another idea were missing subelement-name on any UDT-variable means to use the first subelement.
    Last edited by ReneMiner; 10-04-2015 at 08:10.
    I think there are missing some Forum-sections as beta-testing and support

Similar Threads

  1. type-constructor-ideas
    By ReneMiner in forum Suggestions/Ideas discussions
    Replies: 6
    Last Post: 04-10-2013, 21:26
  2. Strings and data type
    By Henry in forum File
    Replies: 2
    Last Post: 28-06-2011, 12:56
  3. Type 0,1,2,3 Civilisations
    By Charles Pegge in forum Shout Box Area
    Replies: 4
    Last Post: 07-01-2010, 02:21
  4. Array vs type optimization
    By MouseTrap in forum Power Basic
    Replies: 6
    Last Post: 04-03-2009, 11:05

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
  •