Results 1 to 10 of 15

Thread: How to bit shift in ThinBasic ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Member
    Join Date
    Aug 2015
    Location
    Keralam, India
    Posts
    121
    Rep Power
    21

    How to use constructor overloading ?

    Hi all,
    I need to use overloaded constructors for RGB type. One ctor will receive a long parameter and another will receive 3 byte parameters. But now thinbasic is stop working when i use two _create functions inside the type.
    Sorry for the title. I can't edit it.
    Last edited by kcvinu; 14-04-2021 at 10:56.

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

    thinBasic does not support function overloading and/or multiple constructors at the moment.


    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

  3. #3
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,530
    Rep Power
    171
    the _Create-function is (as _Destroy or _Get and _Set) developed not to be called. They are invoked internally in certain moments and act as events.<br><br>to initialize your types you can create a function named as "Init" or "AfterCreation" / whatever as long it starts with an alphabet char. <br>Underscore might be defined as word/char (\w) in regex but is actually not [A-Za-z]<br>when you want to use a technique as Overloading parameters - its difficult for type-functions to develop but for "normal functions" you can use different approaches to pass different&nbsp; parameter-types either byref or byval to a function that will check what is passed to it and call the dedicated function for the received count and type of parameters.&nbsp;<br>Your friends are keywords as&nbsp;<br><br>Optional<br>As Variant<br>As AnyType&nbsp;<br>...(Any) As ...<br><br>for headline of the function that "borrows" the common shared name to the different functions.<br><br>What you have to decide in advance is if are all parameters to pass byval or all byRef / will you need one byref always or 2 - are they optional or not and haw many will be byval - for the function that uses the less parameters then you can plan how to order these. Alike all child-functions will receive 1 byref parameter always and one optional byref and all will have at least 2 parameters byval and one optional byval ... of course the optional parameters are to pass at the end and non-optional before.&nbsp;<br>ByRef means it works with some memory address that could be passed byval as well if the function knows the type to deal with. And Variants allow to receive different variable types and you can sort them by VariantVT to use either Variant$ and take it as String or Variant# wich will whatever the parameter contains in numeric way.&nbsp;<br><br><br>If its like homogennous parameters in a row consider the use of variadic parameters that will receive an infinite bunch of same type in a row and hold the value as you know from any array. So if there is a parameter that is always present, but it differs how many of those are up to come then this can be a variadic parameter.<br>the actual functions that shall share the same name for the user are still different functions and the main-function - Lets name it DoSomething() will call the correct one depending what the user has passed.<br><br>
    <br><br>Function Do something(ByRef anObject As AnyType,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Byval position(ANY) as PointApi,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Byval vParam1 as Variant, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;optional byval vParam2 as Variant,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Byref pOtherObject As myUDTVar Ptr [,...]) As String<br>&nbsp;<br>' the function seperates now what to process under the name "DoSomething" where depending on the parameters differnt things will be done. this function "knows" the name of itself:<br><br>string thisFunc=FunctionName<br>long passedParametersCount =Function_CParams&nbsp;<br>
    
    <br>&nbsp;it could determine typeOf(anObject) or just pass it further byref<br>&nbsp;the position can be different amount but at least 1 must be given. The variadic parameters must be <br>&nbsp;passed inbetween parenthesis as&nbsp;<br><br>
    <br>Long X=DoSomething(W as tWindow, (P1, P7, P5, P3), "wash")<br>
    
    <br>and&nbsp;<br>
    <br>String IcanSee = DoSomething(B as tButton, (p1,p2), 5, "push")&nbsp;&nbsp;<br>
    
    <br><br>Depending on what TypeOf(anObject)<br>and the CountOf(position)<br>[ Select Case] VariantVT(vParam1)&nbsp;<br>&nbsp; &nbsp; Case %VT_Asciiz, 8 ' we have a string<br>&nbsp; &nbsp; &nbsp; sValue = Variant$(vParam1)&nbsp;<br>&nbsp; &nbsp;Case %VT_Ext ' we have a number<br>...<br>Function_cParams tells how many altogether were passed.<br>when this function passes the received result of the function that it called depending on parameters<br>back&nbsp; to the caller in form of a string/ thinbasic "knows" what the caller expects and even if is a byte or an udt that he might expect - it will be the sequence of bytes that you can hand over in a dynamic string.<br><br>You can not only decide by the count and kind of parameters but as well with the content of some.<br>lets say you make the last non-optional parameter and the ones before to be variants and depending if it is a string-variant-type your delegation-call can be as simple as<br><br><span style="color:#0000cd;"><span style="font-family:courier new;"><strong>Call_IfExists "" &amp; Replace$(Function_Name, "TH", Variant$(vParam1)) (anObject, position )<br></strong><span style="font-family:arial;"><br>and it would call something as DoSomeWashing or DoSomePushing from here</span><strong>&nbsp;<br></strong><span style="font-family:arial;">The double double-quote will preven it from misinterpreting maybe a string or its own function-name in front but bame sure to use the literal string content to create a functions name...i hope contains some ideas for you


    soorry the second time today it does that. i am not in the mood to remove the mess made by some strange html bug na
    Last edited by ReneMiner; 23-04-2021 at 20:13.
    I think there are missing some Forum-sections as beta-testing and support

  4. #4
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,530
    Rep Power
    171
    before i manually fix it again up there
    i place the thing that will do it whenever it occurs again and pick these html-tags out

     uses "console" ', "inet" '"brains"
     
     printl "copy the text onto clipboard and press any key to continue, [esc] to abort"
     if waitkey()="[ESC]" then stop  
     
    string sTextIn =Replace$( clipboard_getText, "<br>" , CRLF)
    
    ' string sTextIn = inet_urlgetstring( "https://www.thinbasic.com/community/showthread.php?13111-How-to-bit-shift-in-ThinBasic&p=96021&viewfull=1#post96021") ' <<< not working...
    ' sTextIn = replace$(sTextIn, "<br>", CRLF)
    
     sTextIn = remove$(sTextIn, "&nbsp;") 
     sTextIn = remove$(sTextIn, "&amp;") 
     local char(lenf(sTextIn)) as byte At StrPtr(sTextIn)
    byte bOpen = asc("<")
    byte bClose = asc(">")
      
    long lStart
                          
    do
       
          select case  Array scan char(lStart+1), =bOpen         
          case 0
                ' get all until the last and be done     
                print Memory_get(strptr(sTextIn) + lStart, strptrlen(strptr(sTextIn))-lStart )
                exit do
          case 1 
             
            ' no chars inbetween   lStart and lStart +1 
            lStart += 1  
          case else 
            print memory_get(strptr(sTextIn)+lStart,Selectexpression-1)     
            lStart += Selectexpression 
         end select    
         if lStart < ubound(char) then lStart += array scan char(lStart+1) , =bClose
     
    loop until lStart >=Ubound(char)
    printl
    printl "any key to end"
    waitkey
    
    Last edited by ReneMiner; 23-04-2021 at 23:19.
    I think there are missing some Forum-sections as beta-testing and support

  5. #5
    Member
    Join Date
    Aug 2015
    Location
    Keralam, India
    Posts
    121
    Rep Power
    21
    @Rene Miner & @Petr
    The one and only easy workaround in front of me is this.
    type Sample
      iVal As Integer
      sVal as String
      bVal As Boolean
      InitSample1 As Function
      InitSample2 As Function
    End type
    
    function Sample.InitSample1( iv As Integer, sv as String)  
      With Me
        .iVal = iv
        .sVal = sv
      End with  
    End function
    function Sample.InitSample2( iv As Integer, sv as String, bv As Boolean)  
      With Me
        .iVal = iv
        .sVal = sv
        .bVal = bv
      End with  
    End function
    
    Dim sp as Sample
    sp.InitSample1( 25, "Vinod")
    printl("sVal is = ", sp.sVal)
    
    I hope you people can make thinBasic better.

  6. #6
    Member
    Join Date
    Aug 2015
    Location
    Keralam, India
    Posts
    121
    Rep Power
    21
    @Rene Miner,
    (as _Destroy or _Get and _Set)
    When I read this words from your comment, I suddenly typed "Set" in thinAir and it recognize it as a keyword. But Then I search in Sample script folder to find an example with "Set" & "Get", but I couldn't find any. Could you please show me an example ?
    @Petr,
    How to write a property in an UDT ? The "Private" keyword is making no difference in script. Does the UDT section in thinBasic is incomplete ?

Similar Threads

  1. Is there a bit-shift function?
    By ISAWHIM in forum thinBasic General
    Replies: 18
    Last Post: 29-09-2008, 17:05
  2. For SHIFT keyword
    By ErosOlmi in forum Samples for help file
    Replies: 0
    Last Post: 26-05-2007, 10:25

Members who have read this thread: 4

Posting Permissions

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