Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: OOP ideas

  1. #11
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171
    I rewrote it a little bit using two different "classes" with two functions that have the "same name" (___.abc) at user-side.

    ' This script actually runs.
    Uses "console"
    
    ' -------------------------------------------
    'Begin Class 1       
     
      Type pseudoclass1   
        someVar    As Long
        Static abc As DWord '= Function_GetPtr(abc1)
      End Type             
      Function abc1(ByVal pData As DWord, ByVal xxx As Long ) As Long
       ' this one awaits pointer
      
        Local ME As pseudoclass1 At pData
      
        Return xxx * 2 + ME.someVar - 1000     
      
      End Function   
    
    'End Class 1
    ' -------------------------------------------
    
    Dim myObject1 As pseudoclass1
    
    ' have to set this manually here:
    myObject1.abc = Function_GetPtr(abc1)
    
    ' -------------------------------------------
    'Begin Class 2
    
      Type pseudoclass2   
         otherVar   As Long
         Static abc As DWord ' = Function_GetPtr(abc2)
      End Type             
      Function abc2( ByRef ME As pseudoclass2, ByVal xxx As Long ) As Long
      ' different approach to determine ME here...probably no good for nested types...  
      
        Return xxx * 2 + ME.otherVar - 2000
      
      End Function   
    
    'End Class 2 
    ' -------------------------------------------
    
    Dim myObject2(3) As pseudoclass2     
    myObject2(1).abc = Function_GetPtr(abc2)
     
    ' Test 
    Long lResult
    myObject1.someVar = 1000
    myObject2(2).otherVar = 2000
    
    Call myObject1.abc (VarPtr myObject1, 21) To lResult
    PrintL lResult
    
    Call_IfExists myObject2(2).abc ( myObject2(2), 21) To lResult
    PrintL lResult
     
    WaitKey
    
    Now only needs some Begin-End-Closure around - so the Functions get embedded into the "Type" and the pointer gets set immediately (static the same to all objects of this "class" )
    - and of course something that informs the "embedded" function which element of the Type currently to work with ("ME/THIS") would be better than to have pass always the var byref or its pointer.

    Perhaps can be achieved through a different behavior of Call when passed function-ptr is part of "class"-structure - so identified as "method" -or even proceeding such without keyword "call"
    Last edited by ReneMiner; 26-08-2013 at 19:46.
    I think there are missing some Forum-sections as beta-testing and support

  2. #12
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,533
    Rep Power
    171
    Getting fresh:

    ' This script does not run - yet...but equals the above
    
    Uses "console"
    
    ' -------------------------------------------
    CLASS Class1       
      
      someVar    As Long
      METHOD abc( ByVal xxx As Long ) As Long
       
        Return xxx * 2 + THIS.someVar - 1000     
       
      End METHOD  
     
    End CLASS
    ' -------------------------------------------
    New myObject1 As Class1 
     
    ' -------------------------------------------
    CLASS Class2
     
      otherVar   As Long
      METHOD abc( ByVal xxx As Long ) As Long
       
        METHOD = xxx * 2 + THIS.otherVar - 2000
       
      End METHOD  
     
    End CLASS   
    ' -------------------------------------------
    Dim myObject2(3) As New Class2  ' maybe DIM also would serve?     
    
    ' -------------------------------------------
    ' Test 
    Long lResult
    myObject1.someVar = 1000
    myObject2(2).otherVar = 2000
     
    lResult =  myObject1.abc(21) 
    PrintL lResult
     
    lResult = myObject2(2).abc(21)
    PrintL lResult
      
    WaitKey
    
    ...awaiting comments
    Last edited by ReneMiner; 26-08-2013 at 19:52.
    I think there are missing some Forum-sections as beta-testing and support

  3. #13
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,129
    Rep Power
    732
    Hi Rene,

    I like the approach in second post more - intuitive, no pointer struggle


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  4. #14
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,782
    Rep Power
    10
    Wow: you guys are great!
    Great ideas, great suggestions, great thoughts ... BUT ...

    sorry, I was not talking about OOP here but just about another optional ways to handle DIALOGs CALLBACKs events and, if working fine, possibly extend to CONTROLs events.
    Just that.

    I'm really fascinated by all your ideas on OOP but this is not the post, sorry

    OOP is something I would really love to have in thinBasic but something not just around the corner, something for the next months maybe.

    So, do not worry and keep going on on this brain-storming, all ideas will be useful at the right time.

    Ciao
    Eros

    PS: maybe I will split first post from the others changing subject.
    Last edited by ErosOlmi; 26-08-2013 at 20:33.
    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

Page 2 of 2 FirstFirst 12

Similar Threads

  1. ? about thinAir TOOLS options
    By GSAC3 in forum thinAir General
    Replies: 21
    Last Post: 21-12-2007, 08:32
  2. New karma options
    By ErosOlmi in forum General
    Replies: 2
    Last Post: 13-09-2006, 19:35
  3. New Options Management
    By RobertoBianchi in forum thinAir General
    Replies: 3
    Last Post: 24-02-2006, 13:48

Members who have read this thread: 0

There are no members to list at the moment.

Tags for this Thread

Posting Permissions

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