Results 1 to 6 of 6

Thread: heapy

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    55
    Posts
    1,554
    Rep Power
    174

    heapy

    still in progress so i can not post all of it yet,

    but a small Unit of it that is just to make a Dword behave like some dynamic string-array and that unit runs pretty well already.

    It's really simple so it allows to append dynamic string arrays in a straight row of pointers as lines of text.

    Now this is a demo-script to test the functions of the attached unit below.

    here some tasty snoop-in (Edit: attachement removed, syntax changed a little, download far below contains actual example)

    Uses "console"
    ' needs 1.9.13/14 + latest thincore.dll
     
    #INCLUDE "Heap_Text.tBasicU"
     
    ' ----------------------------------------------------------------------------------
    ' TEST Heap_Text 01:
    ' --------------------------    
    
    ' Heap_Text does only have a few public functions
    
    
    Function TBMain()   
    
      Dim hText As Heap_Text
                                    ' usually would be part of udt...
                                    
      hText.Set$("Hello world")     ' _.Set$() to set data
      PrintL hText.Get$()           ' _.Get$() to get all data at once
      PrintL
                                    ' _.Add$("...", LineNumber) to add to this line
      hText.Add$("...how are you all?", 1)      
                                    ' _.Add$("...") to add a new line
      hText.Add$("this should be a new line")
      
      PrintL hText.Get$(1)           ' _.Get$(Linenumber) to get data of a certain line
      PrintL hText.Get$(hText.Lines) ' _.Lines() will get the last line-number          
      
      PrintL $CRLF & "-----------------------key to continue"
      WaitKey
      PrintL
       
      hText.Set$("this is one line", 1)   ' _.Set$ will kill old lines 
      hText.Set$("this is a line too", 2) ' line number 2 will be overwritten also
      ' automatic creates empty lines...
      hText.Set$("and a little lower", 5)
      
      hText.Set$("this is line 6", 6)
      hText.Set$("this is line 4", 4)
       
      Local i As Long
      ' loop through all lines & read out
      
      For i = 1 To hText.Lines()     ' _.Lines() returns actual count of lines 
        PrintL i, hText.Get$(i)         '  demand a certain line
      Next                  
      
        
      PrintL $CRLF & "-----------------------key to continue"
      WaitKey
      PrintL
      
      ' now insert a few lines at once
      hText.Add$( "Hello world" & $TAB & "This is" & $TAB & "multiline" & $TAB & "inserting", _
                 3, $TAB  ) ' starting at the 3rd line, delimiter is $Tab  
      
                   
      ' and list all at once, delimited by $CRLF  - just don't pass a line-number
      PrintL hText.Get$( , $CRLF)
      PrintL
      
      PrintL
      PrintL $CRLF & "-----------------------key to continue"
      WaitKey
      PrintL
      ' free lines 2, 3, 4 and 5
      
      hText.Free(2,5)                               ' _.Free(startLine, EndLine) 
                                                    ' no endline then only startline
                                                    ' no line or 0 to free all               
      
      PrintL "freed 4 lines of text" & $CRLF & "..."
      
      
      hText.Add$("just to test the add$-function")  ' _.Add$ to add data at the end
      htext.Add$("... try to enlarge line 3", 3)    ' _.Add$("...", linenumber) 
      hText.Add$("far down as line 11 added", 11)
      hText.Set$("overwrite two lines" & $CRLF & "starting at line 8", 8, $CRLF) 
      
      For i = 1 To hText.Lines()
        PrintL i, HEAP_Get( hText.GetPtr(i) )
      Next                                                                 
      
      PrintL
      PrintL $CRLF & "-----------------------key to continue"
      WaitKey
      PrintL
      PrintL "free 2 more lines:"
      hText.Set$("", 6)                             ' kill line 6
      htext.Free(10)                                ' kill what previously was line 11
      
      
      PrintL hText.Get$(,$CRLF)
       
      hText.Free()                                  ' kill all
      
      PrintL $CRLF & "----------------------------key to end"
      WaitKey
      
    End Function
    
    We have an anniversary to celebrate on wednesday:


    thinBasic has type-functions for one year already
    Last edited by ReneMiner; 16-10-2014 at 14:02.
    I think there are missing some Forum-sections as beta-testing and support

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
  •