Results 1 to 6 of 6

Thread: another weird Alias-thought

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

    another weird Alias-thought

    imagine the following, you have some standard-vartype as byte, long, dword and want to give it functions...

    so it's like an udt-variable that has no further udt-elements but can have functions so it's not required to create an additional list of subitems that have to be part of the variables name then

    ???

    maybe like this

    ' you know what this does:
    
    Alias Dword As DataPtr
    
    ' ???
    
    ' but now imagine this simple example:
    
    Type Alias DWord As DataPtr  ' means this Type DataPtr consists of one Dword only
       ' only functions allowed here !!! 
    ' -  but statics were thinkeable... ;)
       GetData As Function
       SetData As Function
    End Type
    
    Function DataPtr.GetData() As String
      Return Heap_Get(Me)
    End Function
    
    Function DataPtr.SetData(Byval sData as String) As Boolean
      If Heap_Size(Me) Then Heap_Free(Me)
      If StrPtrLen(StrPtr(sData)) Then  
        Me = Heap_AllocByStr(sData)
        Function = (Me <> 0 )
      Else
        Me = 0
        Function = True
      Endif
    End Function
    
    
    
    ' lot's of ideas for this...
    ' examples:
    Dim myPtrs(Expression) as DataPtr [At ...]
    
    Type t_XYZ
      pData as DataPtr
       '...
    End Type
    
    Type Alias TBGL_tRGBA As myColor   ' would built-in udt work too?
    '...
    End Type
    
    Type myStuff Extends DataPtr  ' also a nice one then...
    '...
    End Type
    
    
    Type Alias Long As Windowstate  ' should be simple then
      Minimize As Function
      Maximize As Function
    '...
    End Type
    
    Type Alias String As Username   ' could be a little tricky with strings...
    '...
    End Type
    Type Alias String As Password   ' but user can use either StrPtr(Me) etc.
    '...                            or heap could help out here to store these 
    End Type
    
    and we could have built-in-vartypes that have user-definded functions.... think of the possibilities - each variable could behave different by itself...

    currently there's some "workaround" since it does not work using "Me" without ".pData" do some overlay at me

    see below (runs)
    Uses "console"
    
    Type t_DataPtr
    'since simply
    '  Dword '<<< will ERROR
      pData As DWord   ' this is just to occupy the space but never used as such...
      SetData As Function
      GetData As Function
    End Type  
    
    Function t_DataPtr.GetData() As String
      Local lPtr As DWord At VarPtr(Me)
      
      Return HEAP_Get(lPtr)
    End Function
     
    Function t_DataPtr.SetData(ByVal sData As String) As Boolean
      Local lPtr As DWord At VarPtr(Me)
      
      If HEAP_Size(lPtr) Then HEAP_Free(lPtr)
      
      If StrPtrLen(StrPtr(sData)) Then 
        lPtr = HEAP_AllocByStr(sData)
        Function = ( lPtr <> 0 )
      Else
        lPtr = 0
        Function = TRUE
      EndIf
    End Function
    
    Dim x As t_dataptr
    
    If x.setData("this test") Then
      PrintL x.GetData() & " was successful"
    Else
      PrintL "test failed"  
    EndIf 
    
    WaitKey
    
    not just for storing dataptrs and data at heap but also to have variables that may limit themselves or react on certain actions under certain circumstances.

    Edit:
    maybe no alias but just

    Type As Long t_Windowstate
      Minimize As Function
    '...
    End Type
    
    Last edited by ReneMiner; 01-10-2014 at 15:53.
    I think there are missing some Forum-sections as beta-testing and support

  2. #2
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171
    ... the thing is: i just want to have a long- or dword-, byte-, quad-, whatever-simple type with functions - according to it's name ("alias"). So no "x.pData" but just x since x is supposed to be just a dword, byte, quad, whatever. so if defining some udt-variable "alias/as" dword, byte etc. the udt just consists of that single variable-type and the udt-variables name should be enough to access it - but no ".UDT_SubElementsName" needed in this case because it's the only one.
    Last edited by ReneMiner; 01-10-2014 at 20:51.
    I think there are missing some Forum-sections as beta-testing and support

  3. #3
    VisualBasic 6 (and FBSL v3, for that matter) utilize the word Default in a Type declaration to set forth the member in that UDT that can be assessed without referring to its member name. For example:

    Type MySize
       Default Area    As Long
               Length  As Long
               Breadth As Long
    End Type
    
    Dim Size As MySize
    
    Size.Length  = 2
    Size.Breadth = 2
    Size = Size.Length * Size.Breadth
    
    MsgBox Size ' popups 4 that's actually Size's Area field
    
    So Default would be a legit 3rd-generation BASIC keyword to denote what you want:

    Type DoMinimize
        Default Shrink As Function
    End Type
    
    Dim Minimize As DoMinimize
    
    Minimize hMyWnd ' Shrink your window
    



    (P.S. If thinBasic were not the only BASIC you care about, it would be much easier and less verbose for you to express your morning ideas.)
    Mike
    (3.6GHz i5 Core Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, x64 Windows 7 Ultimate Sp1)

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

    private-thoughts

    however its possible to have variables as %myNumConst or $myStringConst to be unchangeable once initialized. So there's a way to block these somehow...

    if this kind of udt that just can consist of one simple variable as in example above can just be changed through keyword "ME" when currently inside a function that's pointer should be identic to one that is stored in the udt-structure then we could have "privates".

    it just would require that assigning or reading values from variables of this type are "unaccesseable" - except if replaced through "Me"
    But it would also require that the functions (that are not declared as private) are accesseable if the real variables name is used


    +Mike
    thanks for your reply, it's indeed the case that i am not a professional programmer and none forces me to code. thinBasic in the meantime has implemented a few of my thoughts and it's becoming some perfectly customized language - it's fun to me. If i'd like to use another language then i would post into their forums
    I think there are missing some Forum-sections as beta-testing and support

  5. #5
    If i'd like to use another language then i would post into their forums
    Perhaps. But there's at least one where you can't -- not any more.
    Mike
    (3.6GHz i5 Core Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, x64 Windows 7 Ultimate Sp1)

  6. #6
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171
    Back to the reason of this thread, not for the private matter but for the possibility to have "simple variables" with functions without the need of any additional subsets. So i can dim foo as t_Type where t_Type can only have functions but no variables noded below, instead it has a value of type "Byte","Long" etc.

    Uses "console"
    
    Alias DWord As DataPtr
    
    Type any_Data Extends DataPtr ' :( won't work...
      Be    As Function
      Is    As Function
    End Type  
    
    dim foo as any_Data   ' foo should be a dword with functions now...
    ' foo.Be("some data") should be valid 
    ' inside Type-function "Me" would be a simple Dword and not been followed by a dot.
      
    PrintL " -- key to end --"
    WaitKey
    

    Mike,
    might be that vb6-support was stopped in march 2008 - or is your forum down?
    Last edited by ReneMiner; 04-10-2014 at 13:55.
    I think there are missing some Forum-sections as beta-testing and support

Similar Threads

  1. Search function of forum gives weird results
    By Michael Hartlef in forum General
    Replies: 9
    Last Post: 03-10-2008, 12:51
  2. Replies: 0
    Last Post: 06-07-2007, 00:55
  3. weird add button error
    By sandyrepope in forum UI (User Interface)
    Replies: 4
    Last Post: 01-07-2007, 12:53

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
  •