No announcement yet.

Best way to set RichEdit text buffer?

  • Filter
  • Time
  • Show
Clear All
new posts

  • Best way to set RichEdit text buffer?

    Since a user can select the entire text within a RichEdit control, capturing the selected text means I have to provide a buffer larger enough to hold the maximum amount of text the RE can hold. In my app, I've set that using EM_LIMITTEXT to 1MB.

    My question is what is the best way to provide the appropriately sized buffer. In most of the examples I've seen, the buffer sizes are relatively small - I haven't seen an example with a huge buffer size.

    The two methods I've considered are:

    Create a global buffer variable using the RE size limit (should be slightly bigger, I suppose). No #STACK required. Global variable size limits are huge.

    #Compile Exe
    #Dim All
    %RELimit = &H100000&
    Global REBuffer As Asciiz * %RELimit
    Function PBMain () As Long
    End Function
    Create a Local variable, but using #STACK to make sure the SUB stack is large enough to hold the REBuffer.

    #Compile Exe
    #Dim All
    #Stack &H200000&  'something bigger than REBuffer
    %D = &H100000&
    Function PBMain () As Long
    Call MySub
    End Function
    Sub MySub
       Local REBuffer As Asciiz * %D
    End Sub
    In this last option, I could also use a string value, with some variation on this:

    Local sBuffer As String
    sBuffer = Space$(%D) + Chr$(0)
    Is there a common approach to this problem?

  • #2
    Buffer$= STRING$(BufferSize&,0) 
    GLOBAL MEM ALLOC  Buffersize& to hMem
    pBuff = malloc(size)  ' note 1 
    REDIM  buff(BufferSize& -1) AS BYTE
    LOCAL|STATIC\GLOBAL|THREADED  Buffer AS STRING * %Buffersize  [ or AS ASCIIZ * %BUffersize + 1)
    Note 1: Code at : malloc, realloc, free for PB/Win32 September 20, 2002)
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]


    • #3
      The best (and proper IMO) way to set and get text with a RichEdit control is to use the following messages:


      Do a search of the forums for examples.

      These commands allow you to move very large blocks of text (in the megabytes), to move only selected portions of the text (what is selected or highlighted) and to move text in either ascii or RTF (RichText Format).

      If you want to get the most out of the RichEdit control start learning how to use these messages.
      Chris Boss
      Computer Workshop
      Developer of "EZGUI"


      • #4
        Maybe this will be of help? or Maybe not

        RTF made Easy for RichEdit
        Engineer's Motto: If it aint broke take it apart and fix it

        "If at 1st you don't succeed... call it version 1.0"

        "Half of Programming is coding"....."The other 90% is DEBUGGING"

        "Document my code????" .... "WHYYY??? do you think they call it CODE? "