In this particular case, the editor gadget will always be read-only, and will always output text generated as RTF formatted, so having the check in there won't be necessary to me. But perhaps it will help someone else
I do have one question though, I noticed in the compiler check there is a call to AllocateMemory() but I don't see any calls to free that memory later. Given that this is a procedure that is designed to print loads and loads of text to a box over time, wouldn't that result in a memory leak or something? Excuse my ignorance I know this likely won't affect me, as I won'y be compiling under older versions anymore, but figured I would ask
mk-soft wrote:The RichEdit control has a check on the text "{\rtf".
If this text is recognized at the beginning, the text is interpreted as UTF8 and translated by Control.
Otherwise, the text is interpreted as Unicode text.
Update v1.03Code: Select all
;-TOP ; ***************************************************************************** ; AddTextRTF by mk-soft, v1.03, 25.03.2018 CompilerIf #PB_Compiler_Version < 550 Procedure UTF8(Text.s) Protected *mem = AllocateMemory(StringByteLength(Text, #PB_UTF8) + 1) If *mem PokeS(*mem, Text, -1, #PB_UTF8) EndIf ProcedureReturn *mem EndProcedure CompilerEndIf Procedure AddTextRTF(Gadget, Text.s , NewLine=#True) If Left(Text, 5) <> "{\rtf " Text = "{\rtf " + Text + "}" EndIf CompilerIf #PB_Compiler_Unicode Protected hEdit = GadgetID(Gadget) Protected ndx = GetWindowTextLength_(hEdit) Protected *szBuffer = UTF8(Text) Protected hFocus = GetFocus_() If ndx And NewLine AddGadgetItem(Gadget, -1, "") EndIf SetFocus_(hEdit); SendMessage_(hEdit, #EM_SETSEL, ndx, ndx) SendMessage_(hEdit, #EM_REPLACESEL, 0, *szBuffer) SetFocus_(hFocus); FreeMemory(*szBuffer) CompilerElse AddGadgetItem(Gadget, -1 , Text) CompilerEndIf EndProcedure ; *****************************************************************************