UltraTextEditor data binding...?

Posted by saquib on 31-Jan-2011 05:34

Hi,

I wish to read the contents of a (possibly large) log file into an UltraTextEditor. What's the best way to do this please?

Can I "bind" the editor to my log file's location (If so how do I do this?) or should I read in the file using a memptr and then convert to a string?

Currently I'm using the Progress IMPORT method which doesn't work well with potentially large files!

   INPUT FROM VALUE(SEARCH("filename")).

  REPEAT:
    IMPORT UNFORMATTED lv-line-om NO-ERROR.
    ultraTextEditor1:Text = ultraTextEditor1:Text + lv-line-om.
  END.

  INPUT CLOSE.

Thanks,

Saquib.

All Replies

Posted by Admin on 31-Jan-2011 06:41

>    ultraTextEditor1:Text = ultraTextEditor1:Text + lv-line-om.

ultraTextEditor1:AppendText (lv-line-om) .

should do a bit better than appending using String-additions.

However try to COPY-LOB the textfile into a LONGCHAR variable first and assign that to the Text property and let us know what performs faster

Or use a System.IO.StreamReader class. MSDN has samples for how to use those.

Posted by saquib on 31-Jan-2011 10:17

Hi Mike,

I eventually got it working with this. As you can see I've had to insert a valid code page into the top of my log file:

   DEFINE PRIVATE VARIABLE lv-whole-line-om AS LONGCHAR NO-UNDO.


    COPY-LOB FROM FILE myFile TO lv-whole-line-om NO-ERROR.
   
    IF ERROR-STATUS:ERROR THEN
    DO:
      MessageBox:Error("A Log file error has occured: " + ERROR-STATUS:GET-MESSAGE(1)).
      RETURN.
    END. 
   
    /* remove the codepage header from the log file editor view
     * N.B. without the code page header we could not copy-lob the log file
     * into a longchar without having to do a CONVERT target source (which
     * was tried but didn't work!)
     */
    ultraTextEditor1:TEXT = REPLACE(lv-whole-line-om,"!ISO8859-1!!ISO8859-1!","").

Thanks,

Saquib.

Posted by Admin on 31-Jan-2011 10:36

>    /* remove the codepage header from the log file editor view

>     * N.B. without the code page header we could not copy-lob the log file

>     * into a longchar without having to do a CONVERT target source (which

>     * was tried but didn't work!)

>     */

What kind of data is in that file? Does it contain data from multiple code pages? I haven't had such problems yet...

Posted by saquib on 01-Feb-2011 02:35

We have a Logger class that is used by our application. It has a method "writeLogItem" that is used by other classes:

writeLogItem code snippet.......

IF SEARCH(ClientSession:LOG_FILE) = ? THEN
  ASSIGN
    lvlNewFile = TRUE.

OUTPUT STREAM strLog TO VALUE(ClientSession:LOG_FILE) APPEND.


/* If the file has just been created add the codepage header
* This is required by the log file viewer for the COPY-LOB.
*/

IF lvlNewFile THEN
   PUT STREAM strLog UNFORMATTED "!ISO8859-1!!ISO8859-1!".
         
PUT STREAM strLog UNFORMATTED
   SUBSTITUTE("&1 &2 [&3] &4":U, STRING(TODAY), STRING(TIME, "HH:MM:SS":U), PROGRAM-NAME(3), lvcLogEntry)
   SKIP.
OUTPUT STREAM strLog CLOSE.

The logger class is called like so:

util.Logger:logDebug(SUBSTITUTE ("lvcError='&1'",STRING(lvcError) )).

logDebug calls writeLogItem.

Thanks,

Saquib.

This thread is closed