Results 1 to 1 of 1

Thread: 3 problems that complicate my life

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

    3 problems that complicate my life

    Boolean Eros_has_developed_Const_Type_Members
    Boolean Eros_has_developed_UDT_ElementName 
    Boolean Eros_has_checked_Alias_Once
    Boolean Eros_was_ambitious
    Boolean Eros_had_time
    
    
    Uses "console"
    PrintL " Problem 1:"
    
    
    ' this some basetype:
    Type t_Test
     Static pTypename As DWord        ' static string not possible :(
                                      ' neither instant assignement...
     X As Long 
     TypeName As Function
    End Type
    Function t_Test.TypeName() As String
      ' read out my type from Me.pTypename
      If Me.pTypename Then Function = Memory_Get(Me.pTypename, Peek(DWord, Me.pTypename-4))
    End Function
    
    ' create some global const that holds/matches the type-name: 
    $t_Test = "t_Test"        
    
    ' assign its pointer to the types static property in advance (before ever using it):
    If pre_initType(StrPtr($t_test)) Then Nop 
     ' ( have to request a result to make sure some using LIKE dimensioned variable
    ' inside pre_initType does not keep the type - applies to type-functions mostly)
    
    ' so this pointer will be the same value to all of this type...                    
    
    
    ' this untyped function creates some local var of a type and assigns the 
    ' pointer where can read out type-name later to a common static property .pTypename
    Function pre_InitType(ByVal constStrPtr As DWord) As Boolean
      Local lVar Like Memory_Get(constStrPtr, Peek(DWord, constStrPtr-4))  
      lVar.pTypename = constStrPtr
    End Function
    
                        
    ' create some extended type now:
    Type t_extest Extends t_test   
    ' can not have "own" Static pTypename.... :(
      y As Long  
      Z As Long       
    End Type                 
    
    ' also create some const to hold the types name
    $t_extest = "t_extest"    
    ' and assign it to the static pType-property
    If pre_initType(StrPtr($t_extest)) Then Nop
    
    
    ' now create a variable of each type and request stored typename            
    Dim t As t_test
    PrintL "await t_test, get  " & t.TypeName()
    
    Dim et As t_extest
    PrintL "await t_extest, get " & et.TypeName()
           
    PrintL $CRLF & "                  --- any key ---"
    WaitKey
    
    
    ' solution thoughts :    
    '-------------------------------------------------------------
    #If Eros_has_developed_Const_Type_Members  
    '-------------------------------------------------------------
     ' allow this:
    Type t_Test2
      Const Typename As String Value "t_Test2"  
      ' no more change possible here 
      ' only able to assign a Const members value here within Type...End Type!    
      
      ' const-members in type are not automatic part of extended types
      ' const-members are - as static members- the same to all elements of this type
      
    End Type
    
    Type t_exTest2 Extends t_Test2  
      Const Typename As String Value "t_exTest2"  
      ' extended types may have matching property-name but different content
    End Type
    
    #EndIf
    
    ' but another simple solution for my specific problem here were
    ' if ALL UDTS would have a built-in property
    ' "{Hidden|Protected|ReadOnly} Typename As String" 
    
    ' that gets filled in when pre-parsing & type-structure gets read in
    ' this would solve any "TypeOf()"-questions for UDTs
    ' perhaps it can only be requested by a core-function as "Type_Name(et)"
    
    
    ' --- but const-type-members still were useful !
    
    
    
    '####################################################################
      
    '-------------------------------------------------------------
    #If Eros_has_developed_UDT_ElementName  
    '-------------------------------------------------------------
    
      PrintL "Problem 2:"
    
    ' retrieve UDT_ElementName,
    
    ' mostly to create function-names from them
    ' but also to retrieve obvious variables names 
    ' and not need to request the same thing multiple times from user
    ' assume the example-types & -variables above
    
    
      Long offset = UDT_ElementOffset(et.Y)      ' would be 4 now since there is 1 long X before
      String sName = UDT_ElementName(et, offset) ' now sName should hold "Y" or instantly ".Y"
      PrintL "UDT_ElementName: "& sName
      
      
    ' solution: no idea... 
    
      #If Eros_was_ambitious  
        
        ' combined - assume offset is known/stored somewhere we could   
        
        Dim data Like Type_Name(et) & UDT_ElementName(et, offset) ' = "t_extest.Y" 
    
         #IF Eros_Had_Time
          ' also we could find out the
          Long n = UDT_ElementNumber(et.Y)   ' would be 2 since et.X is first
          PrintL "we want 2 and get: " & n
        
          ' this would in my special case help to enumerate ControlID from 
          ' a window-type automatic
        #EndIf   
      #EndIf
    #EndIf
    
    '####################################################################
    
    '-------------------------------------------------------------
    #If Eros_has_checked_Alias_Once  
    '-------------------------------------------------------------
    
     PrintL "Problem 3:"
    
      Alias Once As TypeUnitFile  
    ' uncomment 2 lines below after entering valid filename - it will complain even #IF evaluates to 0...  
    
    '  #INCLUDE TypeUnitFile "t_someUnit.tBasicU"  ' <insert a valid unit-filename please>
    '  PrintL "if this gets printed, problem is solved"
      
    ' even if "t_someUnit.tBasicU" would exist it does not get loaded :(
      #If Eros_was_ambitious
        ' all MANDATORY
        
        ' typeUnitfile only must contain 1 type-definition & its type-functions inside
        
        ' no other(plain, unstructured) code will get executed 
        
        ' only CONST UDT-members, maybe also STATIC members can get assigned using VALUE|= expression, 
        ' usage of module-functions as RGB(), Left$(), Ini_GetKey() ...etc possible therefor
        
        ' no global variables can be dimensioned
        
        ' typeUnitFilename composes of Typename and maybe ".tBasicT" as file-extension 
        
        ' best, most easy syntax i can imagine:
        
      ' #Include Type t_myType  '  =  #Include Once "t_myType.tBasicT" 
      ' and now any variable of t_myType could tell me its Type_Name() which is "t_myType"
      #EndIf
    #EndIf
    
    Waitkey
    
    written in thinAir...

    Edit:
    http://www.thinbasic.com/community/p...hp?issueid=486
    http://www.thinbasic.com/community/p...hp?issueid=487
    http://www.thinbasic.com/community/p...hp?issueid=488
    Last edited by ReneMiner; 07-02-2015 at 10:40.
    I think there are missing some Forum-sections as beta-testing and support

Similar Threads

  1. Inner Life Of A Cell
    By John Spikowski in forum Science
    Replies: 0
    Last Post: 23-08-2014, 05:00
  2. Life 3D alfa
    By RobbeK in forum TBGL General
    Replies: 10
    Last Post: 09-11-2013, 00:22
  3. Half Life 2 like...
    By kryton9 in forum Technology
    Replies: 2
    Last Post: 05-11-2011, 04:34
  4. Second Life
    By Charles Pegge in forum Shout Box Area
    Replies: 11
    Last Post: 15-02-2011, 00:31
  5. my life with c++
    By kryton9 in forum C / C++
    Replies: 4
    Last Post: 13-06-2010, 05:00

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
  •